home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / tree.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  114KB  |  4,109 lines

  1. /* Language-independent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the low level primitives for operating on tree nodes,
  22.    including allocation, list operations, interning of identifiers,
  23.    construction of data type nodes and statement nodes,
  24.    and construction of type conversion nodes.  It also contains
  25.    tables index by tree code that describe how to take apart
  26.    nodes of that code.
  27.  
  28.    It is intended to be language-independent, but occasionally
  29.    calls language-dependent routines defined (for C) in typecheck.c.
  30.  
  31.    The low-level allocation routines oballoc and permalloc
  32.    are used also for allocating many other kinds of objects
  33.    by all passes of the compiler.  */
  34.  
  35. #include <setjmp.h>
  36. #include "config.h"
  37. #include "flags.h"
  38. #include "tree.h"
  39. #include "function.h"
  40. #include "obstack.h"
  41. #ifdef __STDC__
  42. #include <stdarg.h>
  43. #else
  44. #include <varargs.h>
  45. #endif
  46. #include <stdio.h>
  47.  
  48. #define obstack_chunk_alloc xmalloc
  49. #define obstack_chunk_free free
  50.  
  51. /* Tree nodes of permanent duration are allocated in this obstack.
  52.    They are the identifier nodes, and everything outside of
  53.    the bodies and parameters of function definitions.  */
  54.  
  55. struct obstack permanent_obstack;
  56.  
  57. /* The initial RTL, and all ..._TYPE nodes, in a function
  58.    are allocated in this obstack.  Usually they are freed at the
  59.    end of the function, but if the function is inline they are saved.
  60.    For top-level functions, this is maybepermanent_obstack.
  61.    Separate obstacks are made for nested functions.  */
  62.  
  63. struct obstack *function_maybepermanent_obstack;
  64.  
  65. /* This is the function_maybepermanent_obstack for top-level functions.  */
  66.  
  67. struct obstack maybepermanent_obstack;
  68.  
  69. /* The contents of the current function definition are allocated
  70.    in this obstack, and all are freed at the end of the function.
  71.    For top-level functions, this is temporary_obstack.
  72.    Separate obstacks are made for nested functions.  */
  73.  
  74. struct obstack *function_obstack;
  75.  
  76. /* This is used for reading initializers of global variables.  */
  77.  
  78. struct obstack temporary_obstack;
  79.  
  80. /* The tree nodes of an expression are allocated
  81.    in this obstack, and all are freed at the end of the expression.  */
  82.  
  83. struct obstack momentary_obstack;
  84.  
  85. /* The tree nodes of a declarator are allocated
  86.    in this obstack, and all are freed when the declarator
  87.    has been parsed.  */
  88.  
  89. static struct obstack temp_decl_obstack;
  90.  
  91. /* This points at either permanent_obstack
  92.    or the current function_maybepermanent_obstack.  */
  93.  
  94. struct obstack *saveable_obstack;
  95.  
  96. /* This is same as saveable_obstack during parse and expansion phase;
  97.    it points to the current function's obstack during optimization.
  98.    This is the obstack to be used for creating rtl objects.  */
  99.  
  100. struct obstack *rtl_obstack;
  101.  
  102. /* This points at either permanent_obstack or the current function_obstack.  */
  103.  
  104. struct obstack *current_obstack;
  105.  
  106. /* This points at either permanent_obstack or the current function_obstack
  107.    or momentary_obstack.  */
  108.  
  109. struct obstack *expression_obstack;
  110.  
  111. /* Stack of obstack selections for push_obstacks and pop_obstacks.  */
  112.  
  113. struct obstack_stack
  114. {
  115.   struct obstack_stack *next;
  116.   struct obstack *current;
  117.   struct obstack *saveable;
  118.   struct obstack *expression;
  119.   struct obstack *rtl;
  120. };
  121.  
  122. struct obstack_stack *obstack_stack;
  123.  
  124. /* Obstack for allocating struct obstack_stack entries.  */
  125.  
  126. static struct obstack obstack_stack_obstack;
  127.  
  128. /* Addresses of first objects in some obstacks.
  129.    This is for freeing their entire contents.  */
  130. char *maybepermanent_firstobj;
  131. char *temporary_firstobj;
  132. char *momentary_firstobj;
  133. char *temp_decl_firstobj;
  134.  
  135. /* This is used to preserve objects (mainly array initializers) that need to
  136.    live until the end of the current function, but no further.  */
  137. char *momentary_function_firstobj;
  138.  
  139. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  140.  
  141. int all_types_permanent;
  142.  
  143. /* Stack of places to restore the momentary obstack back to.  */
  144.    
  145. struct momentary_level
  146. {
  147.   /* Pointer back to previous such level.  */
  148.   struct momentary_level *prev;
  149.   /* First object allocated within this level.  */
  150.   char *base;
  151.   /* Value of expression_obstack saved at entry to this level.  */
  152.   struct obstack *obstack;
  153. };
  154.  
  155. struct momentary_level *momentary_stack;
  156.  
  157. /* Table indexed by tree code giving a string containing a character
  158.    classifying the tree code.  Possibilities are
  159.    t, d, s, c, r, <, 1, 2 and e.  See tree.def for details.  */
  160.  
  161. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  162.  
  163. char *standard_tree_code_type[] = {
  164. #include "tree.def"
  165. };
  166. #undef DEFTREECODE
  167.  
  168. /* Table indexed by tree code giving number of expression
  169.    operands beyond the fixed part of the node structure.
  170.    Not used for types or decls.  */
  171.  
  172. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  173.  
  174. int standard_tree_code_length[] = {
  175. #include "tree.def"
  176. };
  177. #undef DEFTREECODE
  178.  
  179. /* Names of tree components.
  180.    Used for printing out the tree and error messages.  */
  181. #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  182.  
  183. char *standard_tree_code_name[] = {
  184. #include "tree.def"
  185. };
  186. #undef DEFTREECODE
  187.  
  188. /* Table indexed by tree code giving a string containing a character
  189.    classifying the tree code.  Possibilities are
  190.    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
  191.  
  192. char **tree_code_type;
  193.  
  194. /* Table indexed by tree code giving number of expression
  195.    operands beyond the fixed part of the node structure.
  196.    Not used for types or decls.  */
  197.  
  198. int *tree_code_length;
  199.  
  200. /* Table indexed by tree code giving name of tree code, as a string.  */
  201.  
  202. char **tree_code_name;
  203.  
  204. /* Statistics-gathering stuff.  */
  205. typedef enum
  206. {
  207.   d_kind,
  208.   t_kind,
  209.   b_kind,
  210.   s_kind,
  211.   r_kind,
  212.   e_kind,
  213.   c_kind,
  214.   id_kind,
  215.   op_id_kind,
  216.   perm_list_kind,
  217.   temp_list_kind,
  218.   vec_kind,
  219.   x_kind,
  220.   lang_decl,
  221.   lang_type,
  222.   all_kinds
  223. } tree_node_kind;
  224.  
  225. int tree_node_counts[(int)all_kinds];
  226. int tree_node_sizes[(int)all_kinds];
  227. int id_string_size = 0;
  228.  
  229. char *tree_node_kind_names[] = {
  230.   "decls",
  231.   "types",
  232.   "blocks",
  233.   "stmts",
  234.   "refs",
  235.   "exprs",
  236.   "constants",
  237.   "identifiers",
  238.   "op_identifiers",
  239.   "perm_tree_lists",
  240.   "temp_tree_lists",
  241.   "vecs",
  242.   "random kinds",
  243.   "lang_decl kinds",
  244.   "lang_type kinds"
  245. };
  246.  
  247. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  248.  
  249. #define MAX_HASH_TABLE 1009
  250. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  251.  
  252. /* 0 while creating built-in identifiers.  */
  253. static int do_identifier_warnings;
  254.  
  255. /* Unique id for next decl created.  */
  256. static int next_decl_uid;
  257. /* Unique id for next type created.  */
  258. static int next_type_uid = 1;
  259.  
  260. /* Here is how primitive or already-canonicalized types' hash
  261.    codes are made.  */
  262. #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
  263.  
  264. extern char *mode_name[];
  265.  
  266. void gcc_obstack_init ();
  267. static tree stabilize_reference_1 ();
  268.  
  269. /* Init the principal obstacks.  */
  270.  
  271. void
  272. init_obstacks ()
  273. {
  274.   gcc_obstack_init (&obstack_stack_obstack);
  275.   gcc_obstack_init (&permanent_obstack);
  276.  
  277.   gcc_obstack_init (&temporary_obstack);
  278.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  279.   gcc_obstack_init (&momentary_obstack);
  280.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  281.   momentary_function_firstobj = momentary_firstobj;
  282.   gcc_obstack_init (&maybepermanent_obstack);
  283.   maybepermanent_firstobj
  284.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  285.   gcc_obstack_init (&temp_decl_obstack);
  286.   temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
  287.  
  288.   function_obstack = &temporary_obstack;
  289.   function_maybepermanent_obstack = &maybepermanent_obstack;
  290.   current_obstack = &permanent_obstack;
  291.   expression_obstack = &permanent_obstack;
  292.   rtl_obstack = saveable_obstack = &permanent_obstack;
  293.  
  294.   /* Init the hash table of identifiers.  */
  295.   bzero ((char *) hash_table, sizeof hash_table);
  296. }
  297.  
  298. void
  299. gcc_obstack_init (obstack)
  300.      struct obstack *obstack;
  301. {
  302.   /* Let particular systems override the size of a chunk.  */
  303. #ifndef OBSTACK_CHUNK_SIZE
  304. #define OBSTACK_CHUNK_SIZE 0
  305. #endif
  306.   /* Let them override the alloc and free routines too.  */
  307. #ifndef OBSTACK_CHUNK_ALLOC
  308. #define OBSTACK_CHUNK_ALLOC xmalloc
  309. #endif
  310. #ifndef OBSTACK_CHUNK_FREE
  311. #define OBSTACK_CHUNK_FREE free
  312. #endif
  313.   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
  314.           (void *(*) ()) OBSTACK_CHUNK_ALLOC,
  315.           (void (*) ()) OBSTACK_CHUNK_FREE);
  316. }
  317.  
  318. /* Save all variables describing the current status into the structure *P.
  319.    This is used before starting a nested function.  */
  320.  
  321. void
  322. save_tree_status (p, toplevel)
  323.      struct function *p;
  324.      int toplevel;
  325. {
  326.   p->all_types_permanent = all_types_permanent;
  327.   p->momentary_stack = momentary_stack;
  328.   p->maybepermanent_firstobj = maybepermanent_firstobj;
  329.   p->momentary_firstobj = momentary_firstobj;
  330.   p->momentary_function_firstobj = momentary_function_firstobj;
  331.   p->function_obstack = function_obstack;
  332.   p->function_maybepermanent_obstack = function_maybepermanent_obstack;
  333.   p->current_obstack = current_obstack;
  334.   p->expression_obstack = expression_obstack;
  335.   p->saveable_obstack = saveable_obstack;
  336.   p->rtl_obstack = rtl_obstack;
  337.  
  338.   if (! toplevel)
  339.     {
  340.       /* Objects that need to be saved in this function can be in the nonsaved
  341.      obstack of the enclosing function since they can't possibly be needed
  342.      once it has returned.  */
  343.       function_maybepermanent_obstack = function_obstack;
  344.       maybepermanent_firstobj
  345.     = (char *) obstack_finish (function_maybepermanent_obstack);
  346.     }
  347.  
  348.   function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  349.   gcc_obstack_init (function_obstack);
  350.  
  351.   current_obstack = &permanent_obstack;
  352.   expression_obstack = &permanent_obstack;
  353.   rtl_obstack = saveable_obstack = &permanent_obstack;
  354.  
  355.   momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
  356.   momentary_function_firstobj = momentary_firstobj;
  357. }
  358.  
  359. /* Restore all variables describing the current status from the structure *P.
  360.    This is used after a nested function.  */
  361.  
  362. void
  363. restore_tree_status (p, toplevel)
  364.      struct function *p;
  365.      int toplevel;
  366. {
  367.   all_types_permanent = p->all_types_permanent;
  368.   momentary_stack = p->momentary_stack;
  369.  
  370.   obstack_free (&momentary_obstack, momentary_function_firstobj);
  371.  
  372.   if (! toplevel)
  373.     {
  374.       /* Free saveable storage used by the function just compiled and not
  375.      saved.
  376.  
  377.      CAUTION: This is in function_obstack of the containing function.
  378.      So we must be sure that we never allocate from that obstack during
  379.      the compilation of a nested function if we expect it to survive
  380.      past the nested function's end.  */
  381.       obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
  382.     }
  383.  
  384.   obstack_free (function_obstack, 0);
  385.   free (function_obstack);
  386.  
  387.   momentary_firstobj = p->momentary_firstobj;
  388.   momentary_function_firstobj = p->momentary_function_firstobj;
  389.   maybepermanent_firstobj = p->maybepermanent_firstobj;
  390.   function_obstack = p->function_obstack;
  391.   function_maybepermanent_obstack = p->function_maybepermanent_obstack;
  392.   current_obstack = p->current_obstack;
  393.   expression_obstack = p->expression_obstack;
  394.   saveable_obstack = p->saveable_obstack;
  395.   rtl_obstack = p->rtl_obstack;
  396. }
  397.  
  398. /* Start allocating on the temporary (per function) obstack.
  399.    This is done in start_function before parsing the function body,
  400.    and before each initialization at top level, and to go back
  401.    to temporary allocation after doing permanent_allocation.  */
  402.  
  403. void
  404. temporary_allocation ()
  405. {
  406.   /* Note that function_obstack at top level points to temporary_obstack.
  407.      But within a nested function context, it is a separate obstack.  */
  408.   current_obstack = function_obstack;
  409.   expression_obstack = function_obstack;
  410.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  411.   momentary_stack = 0;
  412. }
  413.  
  414. /* Start allocating on the permanent obstack but don't
  415.    free the temporary data.  After calling this, call
  416.    `permanent_allocation' to fully resume permanent allocation status.  */
  417.  
  418. void
  419. end_temporary_allocation ()
  420. {
  421.   current_obstack = &permanent_obstack;
  422.   expression_obstack = &permanent_obstack;
  423.   rtl_obstack = saveable_obstack = &permanent_obstack;
  424. }
  425.  
  426. /* Resume allocating on the temporary obstack, undoing
  427.    effects of `end_temporary_allocation'.  */
  428.  
  429. void
  430. resume_temporary_allocation ()
  431. {
  432.   current_obstack = function_obstack;
  433.   expression_obstack = function_obstack;
  434.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  435. }
  436.  
  437. /* While doing temporary allocation, switch to allocating in such a
  438.    way as to save all nodes if the function is inlined.  Call
  439.    resume_temporary_allocation to go back to ordinary temporary
  440.    allocation.  */
  441.  
  442. void
  443. saveable_allocation ()
  444. {
  445.   /* Note that function_obstack at top level points to temporary_obstack.
  446.      But within a nested function context, it is a separate obstack.  */
  447.   expression_obstack = current_obstack = saveable_obstack;
  448. }
  449.  
  450. /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
  451.    recording the previously current obstacks on a stack.
  452.    This does not free any storage in any obstack.  */
  453.  
  454. void
  455. push_obstacks (current, saveable)
  456.      struct obstack *current, *saveable;
  457. {
  458.   struct obstack_stack *p
  459.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  460.                           (sizeof (struct obstack_stack)));
  461.  
  462.   p->current = current_obstack;
  463.   p->saveable = saveable_obstack;
  464.   p->expression = expression_obstack;
  465.   p->rtl = rtl_obstack;
  466.   p->next = obstack_stack;
  467.   obstack_stack = p;
  468.  
  469.   current_obstack = current;
  470.   expression_obstack = current;
  471.   rtl_obstack = saveable_obstack = saveable;
  472. }
  473.  
  474. /* Save the current set of obstacks, but don't change them.  */
  475.  
  476. void
  477. push_obstacks_nochange ()
  478. {
  479.   struct obstack_stack *p
  480.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  481.                           (sizeof (struct obstack_stack)));
  482.  
  483.   p->current = current_obstack;
  484.   p->saveable = saveable_obstack;
  485.   p->expression = expression_obstack;
  486.   p->rtl = rtl_obstack;
  487.   p->next = obstack_stack;
  488.   obstack_stack = p;
  489. }
  490.  
  491. /* Pop the obstack selection stack.  */
  492.  
  493. void
  494. pop_obstacks ()
  495. {
  496.   struct obstack_stack *p = obstack_stack;
  497.   obstack_stack = p->next;
  498.  
  499.   current_obstack = p->current;
  500.   saveable_obstack = p->saveable;
  501.   expression_obstack = p->expression;
  502.   rtl_obstack = p->rtl;
  503.  
  504.   obstack_free (&obstack_stack_obstack, p);
  505. }
  506.  
  507. /* Nonzero if temporary allocation is currently in effect.
  508.    Zero if currently doing permanent allocation.  */
  509.  
  510. int
  511. allocation_temporary_p ()
  512. {
  513.   return current_obstack != &permanent_obstack;
  514. }
  515.  
  516. /* Go back to allocating on the permanent obstack
  517.    and free everything in the temporary obstack.
  518.  
  519.    FUNCTION_END is true only if we have just finished compiling a function.
  520.    In that case, we also free preserved initial values on the momentary
  521.    obstack.  */
  522.  
  523. void
  524. permanent_allocation (function_end)
  525.      int function_end;
  526. {
  527.   /* Free up previous temporary obstack data */
  528.   obstack_free (&temporary_obstack, temporary_firstobj);
  529.   if (function_end)
  530.     {
  531.       obstack_free (&momentary_obstack, momentary_function_firstobj);
  532.       momentary_firstobj = momentary_function_firstobj;
  533.     }
  534.   else
  535.     obstack_free (&momentary_obstack, momentary_firstobj);
  536.   obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
  537.   obstack_free (&temp_decl_obstack, temp_decl_firstobj);
  538.  
  539.   current_obstack = &permanent_obstack;
  540.   expression_obstack = &permanent_obstack;
  541.   rtl_obstack = saveable_obstack = &permanent_obstack;
  542. }
  543.  
  544. /* Save permanently everything on the maybepermanent_obstack.  */
  545.  
  546. void
  547. preserve_data ()
  548. {
  549.   maybepermanent_firstobj
  550.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  551. }
  552.  
  553. void
  554. preserve_initializer ()
  555. {
  556.   struct momentary_level *tem;
  557.   char *old_momentary;
  558.  
  559.   temporary_firstobj
  560.     = (char *) obstack_alloc (&temporary_obstack, 0);
  561.   maybepermanent_firstobj
  562.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  563.  
  564.   old_momentary = momentary_firstobj;
  565.   momentary_firstobj
  566.     = (char *) obstack_alloc (&momentary_obstack, 0);
  567.   if (momentary_firstobj != old_momentary)
  568.     for (tem = momentary_stack; tem; tem = tem->prev)
  569.       tem->base = momentary_firstobj;
  570. }
  571.  
  572. /* Start allocating new rtl in current_obstack.
  573.    Use resume_temporary_allocation
  574.    to go back to allocating rtl in saveable_obstack.  */
  575.  
  576. void
  577. rtl_in_current_obstack ()
  578. {
  579.   rtl_obstack = current_obstack;
  580. }
  581.  
  582. /* Start allocating rtl from saveable_obstack.  Intended to be used after
  583.    a call to push_obstacks_nochange.  */
  584.  
  585. void
  586. rtl_in_saveable_obstack ()
  587. {
  588.   rtl_obstack = saveable_obstack;
  589. }
  590.  
  591. /* Allocate SIZE bytes in the current obstack
  592.    and return a pointer to them.
  593.    In practice the current obstack is always the temporary one.  */
  594.  
  595. char *
  596. oballoc (size)
  597.      int size;
  598. {
  599.   return (char *) obstack_alloc (current_obstack, size);
  600. }
  601.  
  602. /* Free the object PTR in the current obstack
  603.    as well as everything allocated since PTR.
  604.    In practice the current obstack is always the temporary one.  */
  605.  
  606. void
  607. obfree (ptr)
  608.      char *ptr;
  609. {
  610.   obstack_free (current_obstack, ptr);
  611. }
  612.  
  613. /* Allocate SIZE bytes in the permanent obstack
  614.    and return a pointer to them.  */
  615.  
  616. char *
  617. permalloc (size)
  618.      int size;
  619. {
  620.   return (char *) obstack_alloc (&permanent_obstack, size);
  621. }
  622.  
  623. /* Allocate NELEM items of SIZE bytes in the permanent obstack
  624.    and return a pointer to them.  The storage is cleared before
  625.    returning the value.  */
  626.  
  627. char *
  628. perm_calloc (nelem, size)
  629.      int nelem;
  630.      long size;
  631. {
  632.   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
  633.   bzero (rval, nelem * size);
  634.   return rval;
  635. }
  636.  
  637. /* Allocate SIZE bytes in the saveable obstack
  638.    and return a pointer to them.  */
  639.  
  640. char *
  641. savealloc (size)
  642.      int size;
  643. {
  644.   return (char *) obstack_alloc (saveable_obstack, size);
  645. }
  646.  
  647. /* Print out which obstack an object is in.  */
  648.  
  649. void
  650. print_obstack_name (object, file, prefix)
  651.      char *object;
  652.      FILE *file;
  653.      char *prefix;
  654. {
  655.   struct obstack *obstack = NULL;
  656.   char *obstack_name = NULL;
  657.   struct function *p;
  658.  
  659.   for (p = outer_function_chain; p; p = p->next)
  660.     {
  661.       if (_obstack_allocated_p (p->function_obstack, object))
  662.     {
  663.       obstack = p->function_obstack;
  664.       obstack_name = "containing function obstack";
  665.     }
  666.       if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
  667.     {
  668.       obstack = p->function_maybepermanent_obstack;
  669.       obstack_name = "containing function maybepermanent obstack";
  670.     }
  671.     }
  672.  
  673.   if (_obstack_allocated_p (&obstack_stack_obstack, object))
  674.     {
  675.       obstack = &obstack_stack_obstack;
  676.       obstack_name = "obstack_stack_obstack";
  677.     }
  678.   else if (_obstack_allocated_p (function_obstack, object))
  679.     {
  680.       obstack = function_obstack;
  681.       obstack_name = "function obstack";
  682.     }
  683.   else if (_obstack_allocated_p (&permanent_obstack, object))
  684.     {
  685.       obstack = &permanent_obstack;
  686.       obstack_name = "permanent_obstack";
  687.     }
  688.   else if (_obstack_allocated_p (&momentary_obstack, object))
  689.     {
  690.       obstack = &momentary_obstack;
  691.       obstack_name = "momentary_obstack";
  692.     }
  693.   else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
  694.     {
  695.       obstack = function_maybepermanent_obstack;
  696.       obstack_name = "function maybepermanent obstack";
  697.     }
  698.   else if (_obstack_allocated_p (&temp_decl_obstack, object))
  699.     {
  700.       obstack = &temp_decl_obstack;
  701.       obstack_name = "temp_decl_obstack";
  702.     }
  703.  
  704.   /* Check to see if the object is in the free area of the obstack. */
  705.   if (obstack != NULL)
  706.     {
  707.       if (object >= obstack->next_free
  708.       && object < obstack->chunk_limit)
  709.     fprintf (file, "%s in free portion of obstack %s",
  710.          prefix, obstack_name);
  711.       else
  712.     fprintf (file, "%s allocated from %s", prefix, obstack_name);
  713.     }
  714.   else
  715.     fprintf (file, "%s not allocated from any obstack", prefix);
  716. }
  717.  
  718. void
  719. debug_obstack (object)
  720.      char *object;
  721. {
  722.   print_obstack_name (object, stderr, "object");
  723.   fprintf (stderr, ".\n");
  724. }
  725.  
  726. /* Return 1 if OBJ is in the permanent obstack.
  727.    This is slow, and should be used only for debugging.
  728.    Use TREE_PERMANENT for other purposes.  */
  729.  
  730. int
  731. object_permanent_p (obj)
  732.      tree obj;
  733. {
  734.   return _obstack_allocated_p (&permanent_obstack, obj);
  735. }
  736.  
  737. /* Start a level of momentary allocation.
  738.    In C, each compound statement has its own level
  739.    and that level is freed at the end of each statement.
  740.    All expression nodes are allocated in the momentary allocation level.  */
  741.  
  742. void
  743. push_momentary ()
  744. {
  745.   struct momentary_level *tem
  746.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  747.                         sizeof (struct momentary_level));
  748.   tem->prev = momentary_stack;
  749.   tem->base = (char *) obstack_base (&momentary_obstack);
  750.   tem->obstack = expression_obstack;
  751.   momentary_stack = tem;
  752.   expression_obstack = &momentary_obstack;
  753. }
  754.  
  755. /* Free all the storage in the current momentary-allocation level.
  756.    In C, this happens at the end of each statement.  */
  757.  
  758. void
  759. clear_momentary ()
  760. {
  761.   obstack_free (&momentary_obstack, momentary_stack->base);
  762. }
  763.  
  764. /* Discard a level of momentary allocation.
  765.    In C, this happens at the end of each compound statement.
  766.    Restore the status of expression node allocation
  767.    that was in effect before this level was created.  */
  768.  
  769. void
  770. pop_momentary ()
  771. {
  772.   struct momentary_level *tem = momentary_stack;
  773.   momentary_stack = tem->prev;
  774.   expression_obstack = tem->obstack;
  775.   /* We can't free TEM from the momentary_obstack, because there might
  776.      be objects above it which have been saved.  We can free back to the
  777.      stack of the level we are popping off though.  */
  778.   obstack_free (&momentary_obstack, tem->base);
  779. }
  780.  
  781. /* Pop back to the previous level of momentary allocation,
  782.    but don't free any momentary data just yet.  */
  783.  
  784. void
  785. pop_momentary_nofree ()
  786. {
  787.   struct momentary_level *tem = momentary_stack;
  788.   momentary_stack = tem->prev;
  789.   expression_obstack = tem->obstack;
  790. }
  791.  
  792. /* Call when starting to parse a declaration:
  793.    make expressions in the declaration last the length of the function.
  794.    Returns an argument that should be passed to resume_momentary later.  */
  795.  
  796. int
  797. suspend_momentary ()
  798. {
  799.   register int tem = expression_obstack == &momentary_obstack;
  800.   expression_obstack = saveable_obstack;
  801.   return tem;
  802. }
  803.  
  804. /* Call when finished parsing a declaration:
  805.    restore the treatment of node-allocation that was
  806.    in effect before the suspension.
  807.    YES should be the value previously returned by suspend_momentary.  */
  808.  
  809. void
  810. resume_momentary (yes)
  811.      int yes;
  812. {
  813.   if (yes)
  814.     expression_obstack = &momentary_obstack;
  815. }
  816.  
  817. /* Init the tables indexed by tree code.
  818.    Note that languages can add to these tables to define their own codes.  */
  819.  
  820. void
  821. init_tree_codes ()
  822. {
  823.   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
  824.   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
  825.   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
  826.   bcopy ((char *) standard_tree_code_type, (char *) tree_code_type,
  827.      sizeof (standard_tree_code_type));
  828.   bcopy ((char *) standard_tree_code_length, (char *) tree_code_length,
  829.      sizeof (standard_tree_code_length));
  830.   bcopy ((char *) standard_tree_code_name, (char *) tree_code_name,
  831.      sizeof (standard_tree_code_name));
  832. }
  833.  
  834. /* Return a newly allocated node of code CODE.
  835.    Initialize the node's unique id and its TREE_PERMANENT flag.
  836.    For decl and type nodes, some other fields are initialized.
  837.    The rest of the node is initialized to zero.
  838.  
  839.    Achoo!  I got a code in the node.  */
  840.  
  841. tree
  842. make_node (code)
  843.      enum tree_code code;
  844. {
  845.   register tree t;
  846.   register int type = TREE_CODE_CLASS (code);
  847.   register int length;
  848.   register struct obstack *obstack = current_obstack;
  849.   register int i;
  850.   register tree_node_kind kind;
  851.  
  852.   switch (type)
  853.     {
  854.     case 'd':  /* A decl node */
  855. #ifdef GATHER_STATISTICS
  856.       kind = d_kind;
  857. #endif
  858.       length = sizeof (struct tree_decl);
  859.       /* All decls in an inline function need to be saved.  */
  860.       if (obstack != &permanent_obstack)
  861.     obstack = saveable_obstack;
  862.  
  863.       /* PARM_DECLs go on the context of the parent. If this is a nested
  864.      function, then we must allocate the PARM_DECL on the parent's
  865.      obstack, so that they will live to the end of the parent's
  866.      closing brace.  This is neccesary in case we try to inline the
  867.      function into its parent.
  868.  
  869.      PARM_DECLs of top-level functions do not have this problem.  However,
  870.      we allocate them where we put the FUNCTION_DECL for languauges such as
  871.      Ada that need to consult some flags in the PARM_DECLs of the function
  872.      when calling it. 
  873.  
  874.      See comment in restore_tree_status for why we can't put this
  875.      in function_obstack.  */
  876.       if (code == PARM_DECL && obstack != &permanent_obstack)
  877.     {
  878.       tree context = 0;
  879.       if (current_function_decl)
  880.         context = decl_function_context (current_function_decl);
  881.  
  882.       if (context)
  883.         obstack
  884.           = find_function_data (context)->function_maybepermanent_obstack;
  885.     }
  886.       break;
  887.  
  888.     case 't':  /* a type node */
  889. #ifdef GATHER_STATISTICS
  890.       kind = t_kind;
  891. #endif
  892.       length = sizeof (struct tree_type);
  893.       /* All data types are put where we can preserve them if nec.  */
  894.       if (obstack != &permanent_obstack)
  895.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  896.       break;
  897.  
  898.     case 'b':  /* a lexical block */
  899. #ifdef GATHER_STATISTICS
  900.       kind = b_kind;
  901. #endif
  902.       length = sizeof (struct tree_block);
  903.       /* All BLOCK nodes are put where we can preserve them if nec.  */
  904.       if (obstack != &permanent_obstack)
  905.     obstack = saveable_obstack;
  906.       break;
  907.  
  908.     case 's':  /* an expression with side effects */
  909. #ifdef GATHER_STATISTICS
  910.       kind = s_kind;
  911.       goto usual_kind;
  912. #endif
  913.     case 'r':  /* a reference */
  914. #ifdef GATHER_STATISTICS
  915.       kind = r_kind;
  916.       goto usual_kind;
  917. #endif
  918.     case 'e':  /* an expression */
  919.     case '<':  /* a comparison expression */
  920.     case '1':  /* a unary arithmetic expression */
  921.     case '2':  /* a binary arithmetic expression */
  922. #ifdef GATHER_STATISTICS
  923.       kind = e_kind;
  924.     usual_kind:
  925. #endif
  926.       obstack = expression_obstack;
  927.       /* All BIND_EXPR nodes are put where we can preserve them if nec.  */
  928.       if (code == BIND_EXPR && obstack != &permanent_obstack)
  929.     obstack = saveable_obstack;
  930.       length = sizeof (struct tree_exp)
  931.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  932.       break;
  933.  
  934.     case 'c':  /* a constant */
  935. #ifdef GATHER_STATISTICS
  936.       kind = c_kind;
  937. #endif
  938.       obstack = expression_obstack;
  939.  
  940.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  941.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  942.      which might be wider than a pointer (e.g., long long).  Similarly
  943.      for REAL_CST, since the number of words is machine-dependent due
  944.      to varying size and alignment of `double'.  */
  945.  
  946.       if (code == INTEGER_CST)
  947.     length = sizeof (struct tree_int_cst);
  948.       else if (code == REAL_CST)
  949.     length = sizeof (struct tree_real_cst);
  950.       else
  951.     length = sizeof (struct tree_common)
  952.       + tree_code_length[(int) code] * sizeof (char *);
  953.       break;
  954.  
  955.     case 'x':  /* something random, like an identifier.  */
  956. #ifdef GATHER_STATISTICS
  957.       if (code == IDENTIFIER_NODE)
  958.     kind = id_kind;
  959.       else if (code == OP_IDENTIFIER)
  960.     kind = op_id_kind;
  961.       else if (code == TREE_VEC)
  962.     kind = vec_kind;
  963.       else
  964.     kind = x_kind;
  965. #endif
  966.       length = sizeof (struct tree_common)
  967.     + tree_code_length[(int) code] * sizeof (char *);
  968.       /* Identifier nodes are always permanent since they are
  969.      unique in a compiler run.  */
  970.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  971.       break;
  972.  
  973.     default:
  974.       abort ();
  975.     }
  976.  
  977.   t = (tree) obstack_alloc (obstack, length);
  978.  
  979. #ifdef GATHER_STATISTICS
  980.   tree_node_counts[(int)kind]++;
  981.   tree_node_sizes[(int)kind] += length;
  982. #endif
  983.  
  984.   /* Clear a word at a time.  */
  985.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  986.     ((int *) t)[i] = 0;
  987.   /* Clear any extra bytes.  */
  988.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  989.     ((char *) t)[i] = 0;
  990.  
  991.   TREE_SET_CODE (t, code);
  992.   if (obstack == &permanent_obstack)
  993.     TREE_PERMANENT (t) = 1;
  994.  
  995.   switch (type)
  996.     {
  997.     case 's':
  998.       TREE_SIDE_EFFECTS (t) = 1;
  999.       TREE_TYPE (t) = void_type_node;
  1000.       break;
  1001.  
  1002.     case 'd':
  1003.       if (code != FUNCTION_DECL)
  1004.     DECL_ALIGN (t) = 1;
  1005.       DECL_IN_SYSTEM_HEADER (t)
  1006.     = in_system_header && (obstack == &permanent_obstack);
  1007.       DECL_SOURCE_LINE (t) = lineno;
  1008.       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
  1009.       DECL_UID (t) = next_decl_uid++;
  1010.       break;
  1011.  
  1012.     case 't':
  1013.       TYPE_UID (t) = next_type_uid++;
  1014.       TYPE_ALIGN (t) = 1;
  1015.       TYPE_MAIN_VARIANT (t) = t;
  1016.       TYPE_OBSTACK (t) = obstack;
  1017.       TYPE_ATTRIBUTES (t) = NULL_TREE;
  1018. #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
  1019.       SET_DEFAULT_TYPE_ATTRIBUTES (t);
  1020. #endif
  1021.       break;
  1022.  
  1023.     case 'c':
  1024.       TREE_CONSTANT (t) = 1;
  1025.       break;
  1026.     }
  1027.  
  1028.   return t;
  1029. }
  1030.  
  1031. /* Return a new node with the same contents as NODE
  1032.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  1033.  
  1034. tree
  1035. copy_node (node)
  1036.      tree node;
  1037. {
  1038.   register tree t;
  1039.   register enum tree_code code = TREE_CODE (node);
  1040.   register int length;
  1041.   register int i;
  1042.  
  1043.   switch (TREE_CODE_CLASS (code))
  1044.     {
  1045.     case 'd':  /* A decl node */
  1046.       length = sizeof (struct tree_decl);
  1047.       break;
  1048.  
  1049.     case 't':  /* a type node */
  1050.       length = sizeof (struct tree_type);
  1051.       break;
  1052.  
  1053.     case 'b':  /* a lexical block node */
  1054.       length = sizeof (struct tree_block);
  1055.       break;
  1056.  
  1057.     case 'r':  /* a reference */
  1058.     case 'e':  /* an expression */
  1059.     case 's':  /* an expression with side effects */
  1060.     case '<':  /* a comparison expression */
  1061.     case '1':  /* a unary arithmetic expression */
  1062.     case '2':  /* a binary arithmetic expression */
  1063.       length = sizeof (struct tree_exp)
  1064.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  1065.       break;
  1066.  
  1067.     case 'c':  /* a constant */
  1068.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  1069.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  1070.      which might be wider than a pointer (e.g., long long).  Similarly
  1071.      for REAL_CST, since the number of words is machine-dependent due
  1072.      to varying size and alignment of `double'.  */
  1073.       if (code == INTEGER_CST)
  1074.         {
  1075.           length = sizeof (struct tree_int_cst);
  1076.           break;
  1077.         }
  1078.       else if (code == REAL_CST)
  1079.     {
  1080.       length = sizeof (struct tree_real_cst);
  1081.       break;
  1082.     }
  1083.  
  1084.     case 'x':  /* something random, like an identifier.  */
  1085.       length = sizeof (struct tree_common)
  1086.     + tree_code_length[(int) code] * sizeof (char *);
  1087.       if (code == TREE_VEC)
  1088.     length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
  1089.     }
  1090.  
  1091.   t = (tree) obstack_alloc (current_obstack, length);
  1092.  
  1093.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1094.     ((int *) t)[i] = ((int *) node)[i];
  1095.   /* Clear any extra bytes.  */
  1096.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  1097.     ((char *) t)[i] = ((char *) node)[i];
  1098.  
  1099.   TREE_CHAIN (t) = 0;
  1100.  
  1101.   if (TREE_CODE_CLASS (code) == 'd')
  1102.     DECL_UID (t) = next_decl_uid++;
  1103.   else if (TREE_CODE_CLASS (code) == 't')
  1104.     {
  1105.       TYPE_UID (t) = next_type_uid++;
  1106.       TYPE_OBSTACK (t) = current_obstack;
  1107.     }
  1108.  
  1109.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  1110.  
  1111.   return t;
  1112. }
  1113.  
  1114. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  1115.    For example, this can copy a list made of TREE_LIST nodes.  */
  1116.  
  1117. tree
  1118. copy_list (list)
  1119.      tree list;
  1120. {
  1121.   tree head;
  1122.   register tree prev, next;
  1123.  
  1124.   if (list == 0)
  1125.     return 0;
  1126.  
  1127.   head = prev = copy_node (list);
  1128.   next = TREE_CHAIN (list);
  1129.   while (next)
  1130.     {
  1131.       TREE_CHAIN (prev) = copy_node (next);
  1132.       prev = TREE_CHAIN (prev);
  1133.       next = TREE_CHAIN (next);
  1134.     }
  1135.   return head;
  1136. }
  1137.  
  1138. #define HASHBITS 30
  1139.  
  1140. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  1141.    If an identifier with that name has previously been referred to,
  1142.    the same node is returned this time.  */
  1143.  
  1144. tree
  1145. get_identifier (text)
  1146.      register char *text;
  1147. {
  1148.   register int hi;
  1149.   register int i;
  1150.   register tree idp;
  1151.   register int len, hash_len;
  1152.  
  1153.   /* Compute length of text in len.  */
  1154.   for (len = 0; text[len]; len++);
  1155.  
  1156.   /* Decide how much of that length to hash on */
  1157.   hash_len = len;
  1158.   if (warn_id_clash && len > id_clash_len)
  1159.     hash_len = id_clash_len;
  1160.  
  1161.   /* Compute hash code */
  1162.   hi = hash_len * 613 + (unsigned)text[0];
  1163.   for (i = 1; i < hash_len; i += 2)
  1164.     hi = ((hi * 613) + (unsigned)(text[i]));
  1165.  
  1166.   hi &= (1 << HASHBITS) - 1;
  1167.   hi %= MAX_HASH_TABLE;
  1168.   
  1169.   /* Search table for identifier */
  1170.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1171.     if (IDENTIFIER_LENGTH (idp) == len
  1172.     && IDENTIFIER_POINTER (idp)[0] == text[0]
  1173.     && !bcmp (IDENTIFIER_POINTER (idp), text, len))
  1174.       return idp;        /* <-- return if found */
  1175.  
  1176.   /* Not found; optionally warn about a similar identifier */
  1177.   if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
  1178.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1179.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  1180.     {
  1181.       warning ("`%s' and `%s' identical in first %d characters",
  1182.            IDENTIFIER_POINTER (idp), text, id_clash_len);
  1183.       break;
  1184.     }
  1185.  
  1186.   if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
  1187.     abort ();            /* set_identifier_size hasn't been called.  */
  1188.  
  1189.   /* Not found, create one, add to chain */
  1190.   idp = make_node (IDENTIFIER_NODE);
  1191.   IDENTIFIER_LENGTH (idp) = len;
  1192. #ifdef GATHER_STATISTICS
  1193.   id_string_size += len;
  1194. #endif
  1195.  
  1196.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  1197.  
  1198.   TREE_CHAIN (idp) = hash_table[hi];
  1199.   hash_table[hi] = idp;
  1200.   return idp;            /* <-- return if created */
  1201. }
  1202.  
  1203. /* Enable warnings on similar identifiers (if requested).
  1204.    Done after the built-in identifiers are created.  */
  1205.  
  1206. void
  1207. start_identifier_warnings ()
  1208. {
  1209.   do_identifier_warnings = 1;
  1210. }
  1211.  
  1212. /* Record the size of an identifier node for the language in use.
  1213.    SIZE is the total size in bytes.
  1214.    This is called by the language-specific files.  This must be
  1215.    called before allocating any identifiers.  */
  1216.  
  1217. void
  1218. set_identifier_size (size)
  1219.      int size;
  1220. {
  1221.   tree_code_length[(int) IDENTIFIER_NODE]
  1222.     = (size - sizeof (struct tree_common)) / sizeof (tree);
  1223. }
  1224.  
  1225. /* Return a newly constructed INTEGER_CST node whose constant value
  1226.    is specified by the two ints LOW and HI.
  1227.    The TREE_TYPE is set to `int'. 
  1228.  
  1229.    This function should be used via the `build_int_2' macro.  */
  1230.  
  1231. tree
  1232. build_int_2_wide (low, hi)
  1233.      HOST_WIDE_INT low, hi;
  1234. {
  1235.   register tree t = make_node (INTEGER_CST);
  1236.   TREE_INT_CST_LOW (t) = low;
  1237.   TREE_INT_CST_HIGH (t) = hi;
  1238.   TREE_TYPE (t) = integer_type_node;
  1239.   return t;
  1240. }
  1241.  
  1242. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  1243.  
  1244. tree
  1245. build_real (type, d)
  1246.      tree type;
  1247.      REAL_VALUE_TYPE d;
  1248. {
  1249.   tree v;
  1250.   int overflow = 0;
  1251.  
  1252.   /* Check for valid float value for this type on this target machine;
  1253.      if not, can print error message and store a valid value in D.  */
  1254. #ifdef CHECK_FLOAT_VALUE
  1255.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1256. #endif
  1257.  
  1258.   v = make_node (REAL_CST);
  1259.   TREE_TYPE (v) = type;
  1260.   TREE_REAL_CST (v) = d;
  1261.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1262.   return v;
  1263. }
  1264.  
  1265. /* Return a new REAL_CST node whose type is TYPE
  1266.    and whose value is the integer value of the INTEGER_CST node I.  */
  1267.  
  1268. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1269.  
  1270. REAL_VALUE_TYPE
  1271. real_value_from_int_cst (i)
  1272.      tree i;
  1273. {
  1274.   REAL_VALUE_TYPE d;
  1275.   REAL_VALUE_TYPE e;
  1276.   /* Some 386 compilers mishandle unsigned int to float conversions,
  1277.      so introduce a temporary variable E to avoid those bugs.  */
  1278.  
  1279. #ifdef REAL_ARITHMETIC
  1280.   if (! TREE_UNSIGNED (TREE_TYPE (i)))
  1281.     REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1282.   else
  1283.     REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1284. #else /* not REAL_ARITHMETIC */
  1285.   if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
  1286.     {
  1287.       d = (double) (~ TREE_INT_CST_HIGH (i));
  1288.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1289.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1290.       d *= e;
  1291.       e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
  1292.       d += e;
  1293.       d = (- d - 1.0);
  1294.     }
  1295.   else
  1296.     {
  1297.       d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
  1298.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1299.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1300.       d *= e;
  1301.       e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
  1302.       d += e;
  1303.     }
  1304. #endif /* not REAL_ARITHMETIC */
  1305.   return d;
  1306. }
  1307.  
  1308. /* This function can't be implemented if we can't do arithmetic
  1309.    on the float representation.  */
  1310.  
  1311. tree
  1312. build_real_from_int_cst (type, i)
  1313.      tree type;
  1314.      tree i;
  1315. {
  1316.   tree v;
  1317.   int overflow = TREE_OVERFLOW (i);
  1318.   REAL_VALUE_TYPE d;
  1319.   jmp_buf float_error;
  1320.  
  1321.   v = make_node (REAL_CST);
  1322.   TREE_TYPE (v) = type;
  1323.  
  1324.   if (setjmp (float_error))
  1325.     {
  1326.       d = dconst0;
  1327.       overflow = 1;
  1328.       goto got_it;
  1329.     }
  1330.  
  1331.   set_float_handler (float_error);
  1332.  
  1333.   d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
  1334.  
  1335.   /* Check for valid float value for this type on this target machine.  */
  1336.  
  1337.  got_it:
  1338.   set_float_handler (NULL_PTR);
  1339.  
  1340. #ifdef CHECK_FLOAT_VALUE
  1341.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1342. #endif
  1343.  
  1344.   TREE_REAL_CST (v) = d;
  1345.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1346.   return v;
  1347. }
  1348.  
  1349. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1350.  
  1351. /* Return a newly constructed STRING_CST node whose value is
  1352.    the LEN characters at STR.
  1353.    The TREE_TYPE is not initialized.  */
  1354.  
  1355. tree
  1356. build_string (len, str)
  1357.      int len;
  1358.      char *str;
  1359. {
  1360.   /* Put the string in saveable_obstack since it will be placed in the RTL
  1361.      for an "asm" statement and will also be kept around a while if
  1362.      deferring constant output in varasm.c.  */
  1363.  
  1364.   register tree s = make_node (STRING_CST);
  1365.   TREE_STRING_LENGTH (s) = len;
  1366.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  1367.   return s;
  1368. }
  1369.  
  1370. /* Return a newly constructed COMPLEX_CST node whose value is
  1371.    specified by the real and imaginary parts REAL and IMAG.
  1372.    Both REAL and IMAG should be constant nodes.
  1373.    The TREE_TYPE is not initialized.  */
  1374.  
  1375. tree
  1376. build_complex (real, imag)
  1377.      tree real, imag;
  1378. {
  1379.   register tree t = make_node (COMPLEX_CST);
  1380.  
  1381.   TREE_REALPART (t) = real;
  1382.   TREE_IMAGPART (t) = imag;
  1383.   TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
  1384.   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
  1385.   TREE_CONSTANT_OVERFLOW (t)
  1386.     = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
  1387.   return t;
  1388. }
  1389.  
  1390. /* Build a newly constructed TREE_VEC node of length LEN.  */
  1391. tree
  1392. make_tree_vec (len)
  1393.      int len;
  1394. {
  1395.   register tree t;
  1396.   register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
  1397.   register struct obstack *obstack = current_obstack;
  1398.   register int i;
  1399.  
  1400. #ifdef GATHER_STATISTICS
  1401.   tree_node_counts[(int)vec_kind]++;
  1402.   tree_node_sizes[(int)vec_kind] += length;
  1403. #endif
  1404.  
  1405.   t = (tree) obstack_alloc (obstack, length);
  1406.  
  1407.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1408.     ((int *) t)[i] = 0;
  1409.  
  1410.   TREE_SET_CODE (t, TREE_VEC);
  1411.   TREE_VEC_LENGTH (t) = len;
  1412.   if (obstack == &permanent_obstack)
  1413.     TREE_PERMANENT (t) = 1;
  1414.  
  1415.   return t;
  1416. }
  1417.  
  1418. /* Return 1 if EXPR is the integer constant zero.  */
  1419.  
  1420. int
  1421. integer_zerop (expr)
  1422.      tree expr;
  1423. {
  1424.   STRIP_NOPS (expr);
  1425.  
  1426.   return (TREE_CODE (expr) == INTEGER_CST
  1427.       && TREE_INT_CST_LOW (expr) == 0
  1428.       && TREE_INT_CST_HIGH (expr) == 0);
  1429. }
  1430.  
  1431. /* Return 1 if EXPR is the integer constant one.  */
  1432.  
  1433. int
  1434. integer_onep (expr)
  1435.      tree expr;
  1436. {
  1437.   STRIP_NOPS (expr);
  1438.  
  1439.   return (TREE_CODE (expr) == INTEGER_CST
  1440.       && TREE_INT_CST_LOW (expr) == 1
  1441.       && TREE_INT_CST_HIGH (expr) == 0);
  1442. }
  1443.  
  1444. /* Return 1 if EXPR is an integer containing all 1's
  1445.    in as much precision as it contains.  */
  1446.  
  1447. int
  1448. integer_all_onesp (expr)
  1449.      tree expr;
  1450. {
  1451.   register int prec;
  1452.   register int uns;
  1453.  
  1454.   STRIP_NOPS (expr);
  1455.  
  1456.   if (TREE_CODE (expr) != INTEGER_CST)
  1457.     return 0;
  1458.  
  1459.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  1460.   if (!uns)
  1461.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  1462.  
  1463.   prec = TYPE_PRECISION (TREE_TYPE (expr));
  1464.   if (prec >= HOST_BITS_PER_WIDE_INT)
  1465.     {
  1466.       int high_value, shift_amount;
  1467.  
  1468.       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
  1469.  
  1470.       if (shift_amount > HOST_BITS_PER_WIDE_INT)
  1471.     /* Can not handle precisions greater than twice the host int size.  */
  1472.     abort ();
  1473.       else if (shift_amount == HOST_BITS_PER_WIDE_INT)
  1474.     /* Shifting by the host word size is undefined according to the ANSI
  1475.        standard, so we must handle this as a special case.  */
  1476.     high_value = -1;
  1477.       else
  1478.     high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
  1479.  
  1480.       return TREE_INT_CST_LOW (expr) == -1
  1481.     && TREE_INT_CST_HIGH (expr) == high_value;
  1482.     }
  1483.   else
  1484.     return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
  1485. }
  1486.  
  1487. /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
  1488.    one bit on).  */
  1489.  
  1490. int
  1491. integer_pow2p (expr)
  1492.      tree expr;
  1493. {
  1494.   HOST_WIDE_INT high, low;
  1495.  
  1496.   STRIP_NOPS (expr);
  1497.  
  1498.   if (TREE_CODE (expr) != INTEGER_CST)
  1499.     return 0;
  1500.  
  1501.   high = TREE_INT_CST_HIGH (expr);
  1502.   low = TREE_INT_CST_LOW (expr);
  1503.  
  1504.   if (high == 0 && low == 0)
  1505.     return 0;
  1506.  
  1507.   return ((high == 0 && (low & (low - 1)) == 0)
  1508.       || (low == 0 && (high & (high - 1)) == 0));
  1509. }
  1510.  
  1511. /* Return 1 if EXPR is the real constant zero.  */
  1512.  
  1513. int
  1514. real_zerop (expr)
  1515.      tree expr;
  1516. {
  1517.   STRIP_NOPS (expr);
  1518.  
  1519.   return (TREE_CODE (expr) == REAL_CST
  1520.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
  1521. }
  1522.  
  1523. /* Return 1 if EXPR is the real constant one.  */
  1524.  
  1525. int
  1526. real_onep (expr)
  1527.      tree expr;
  1528. {
  1529.   STRIP_NOPS (expr);
  1530.  
  1531.   return (TREE_CODE (expr) == REAL_CST
  1532.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
  1533. }
  1534.  
  1535. /* Return 1 if EXPR is the real constant two.  */
  1536.  
  1537. int
  1538. real_twop (expr)
  1539.      tree expr;
  1540. {
  1541.   STRIP_NOPS (expr);
  1542.  
  1543.   return (TREE_CODE (expr) == REAL_CST
  1544.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
  1545. }
  1546.  
  1547. /* Nonzero if EXP is a constant or a cast of a constant.  */
  1548.  
  1549. int
  1550. really_constant_p (exp)
  1551.      tree exp;
  1552. {
  1553.   /* This is not quite the same as STRIP_NOPS.  It does more.  */
  1554.   while (TREE_CODE (exp) == NOP_EXPR
  1555.      || TREE_CODE (exp) == CONVERT_EXPR
  1556.      || TREE_CODE (exp) == NON_LVALUE_EXPR)
  1557.     exp = TREE_OPERAND (exp, 0);
  1558.   return TREE_CONSTANT (exp);
  1559. }
  1560.  
  1561. /* Return first list element whose TREE_VALUE is ELEM.
  1562.    Return 0 if ELEM is not it LIST.  */
  1563.  
  1564. tree
  1565. value_member (elem, list)
  1566.      tree elem, list;
  1567. {
  1568.   while (list)
  1569.     {
  1570.       if (elem == TREE_VALUE (list))
  1571.     return list;
  1572.       list = TREE_CHAIN (list);
  1573.     }
  1574.   return NULL_TREE;
  1575. }
  1576.  
  1577. /* Return first list element whose TREE_PURPOSE is ELEM.
  1578.    Return 0 if ELEM is not it LIST.  */
  1579.  
  1580. tree
  1581. purpose_member (elem, list)
  1582.      tree elem, list;
  1583. {
  1584.   while (list)
  1585.     {
  1586.       if (elem == TREE_PURPOSE (list))
  1587.     return list;
  1588.       list = TREE_CHAIN (list);
  1589.     }
  1590.   return NULL_TREE;
  1591. }
  1592.  
  1593. /* Return first list element whose BINFO_TYPE is ELEM.
  1594.    Return 0 if ELEM is not it LIST.  */
  1595.  
  1596. tree
  1597. binfo_member (elem, list)
  1598.      tree elem, list;
  1599. {
  1600.   while (list)
  1601.     {
  1602.       if (elem == BINFO_TYPE (list))
  1603.     return list;
  1604.       list = TREE_CHAIN (list);
  1605.     }
  1606.   return NULL_TREE;
  1607. }
  1608.  
  1609. /* Return nonzero if ELEM is part of the chain CHAIN.  */
  1610.  
  1611. int
  1612. chain_member (elem, chain)
  1613.      tree elem, chain;
  1614. {
  1615.   while (chain)
  1616.     {
  1617.       if (elem == chain)
  1618.     return 1;
  1619.       chain = TREE_CHAIN (chain);
  1620.     }
  1621.  
  1622.   return 0;
  1623. }
  1624.  
  1625. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  1626.    We expect a null pointer to mark the end of the chain.
  1627.    This is the Lisp primitive `length'.  */
  1628.  
  1629. int
  1630. list_length (t)
  1631.      tree t;
  1632. {
  1633.   register tree tail;
  1634.   register int len = 0;
  1635.  
  1636.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  1637.     len++;
  1638.  
  1639.   return len;
  1640. }
  1641.  
  1642. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  1643.    by modifying the last node in chain 1 to point to chain 2.
  1644.    This is the Lisp primitive `nconc'.  */
  1645.  
  1646. tree
  1647. chainon (op1, op2)
  1648.      tree op1, op2;
  1649. {
  1650.  
  1651.   if (op1)
  1652.     {
  1653.       register tree t1;
  1654.       register tree t2;
  1655.  
  1656.       for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
  1657.     ;
  1658.       TREE_CHAIN (t1) = op2;
  1659.       for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
  1660.         if (t2 == t1)
  1661.           abort ();  /* Circularity created.  */
  1662.       return op1;
  1663.     }
  1664.   else return op2;
  1665. }
  1666.  
  1667. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  1668.  
  1669. tree
  1670. tree_last (chain)
  1671.      register tree chain;
  1672. {
  1673.   register tree next;
  1674.   if (chain)
  1675.     while (next = TREE_CHAIN (chain))
  1676.       chain = next;
  1677.   return chain;
  1678. }
  1679.  
  1680. /* Reverse the order of elements in the chain T,
  1681.    and return the new head of the chain (old last element).  */
  1682.  
  1683. tree
  1684. nreverse (t)
  1685.      tree t;
  1686. {
  1687.   register tree prev = 0, decl, next;
  1688.   for (decl = t; decl; decl = next)
  1689.     {
  1690.       next = TREE_CHAIN (decl);
  1691.       TREE_CHAIN (decl) = prev;
  1692.       prev = decl;
  1693.     }
  1694.   return prev;
  1695. }
  1696.  
  1697. /* Given a chain CHAIN of tree nodes,
  1698.    construct and return a list of those nodes.  */
  1699.  
  1700. tree
  1701. listify (chain)
  1702.      tree chain;
  1703. {
  1704.   tree result = NULL_TREE;
  1705.   tree in_tail = chain;
  1706.   tree out_tail = NULL_TREE;
  1707.  
  1708.   while (in_tail)
  1709.     {
  1710.       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
  1711.       if (out_tail)
  1712.     TREE_CHAIN (out_tail) = next;
  1713.       else
  1714.     result = next;
  1715.       out_tail = next;
  1716.       in_tail = TREE_CHAIN (in_tail);
  1717.     }
  1718.  
  1719.   return result;
  1720. }
  1721.  
  1722. /* Return a newly created TREE_LIST node whose
  1723.    purpose and value fields are PARM and VALUE.  */
  1724.  
  1725. tree
  1726. build_tree_list (parm, value)
  1727.      tree parm, value;
  1728. {
  1729.   register tree t = make_node (TREE_LIST);
  1730.   TREE_PURPOSE (t) = parm;
  1731.   TREE_VALUE (t) = value;
  1732.   return t;
  1733. }
  1734.  
  1735. /* Similar, but build on the temp_decl_obstack.  */
  1736.  
  1737. tree
  1738. build_decl_list (parm, value)
  1739.      tree parm, value;
  1740. {
  1741.   register tree node;
  1742.   register struct obstack *ambient_obstack = current_obstack;
  1743.   current_obstack = &temp_decl_obstack;
  1744.   node = build_tree_list (parm, value);
  1745.   current_obstack = ambient_obstack;
  1746.   return node;
  1747. }
  1748.  
  1749. /* Return a newly created TREE_LIST node whose
  1750.    purpose and value fields are PARM and VALUE
  1751.    and whose TREE_CHAIN is CHAIN.  */
  1752.  
  1753. tree
  1754. tree_cons (purpose, value, chain)
  1755.      tree purpose, value, chain;
  1756. {
  1757. #if 0
  1758.   register tree node = make_node (TREE_LIST);
  1759. #else
  1760.   register int i;
  1761.   register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
  1762. #ifdef GATHER_STATISTICS
  1763.   tree_node_counts[(int)x_kind]++;
  1764.   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
  1765. #endif
  1766.  
  1767.   for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
  1768.     ((int *) node)[i] = 0;
  1769.  
  1770.   TREE_SET_CODE (node, TREE_LIST);
  1771.   if (current_obstack == &permanent_obstack)
  1772.     TREE_PERMANENT (node) = 1;
  1773. #endif
  1774.  
  1775.   TREE_CHAIN (node) = chain;
  1776.   TREE_PURPOSE (node) = purpose;
  1777.   TREE_VALUE (node) = value;
  1778.   return node;
  1779. }
  1780.  
  1781. /* Similar, but build on the temp_decl_obstack.  */
  1782.  
  1783. tree
  1784. decl_tree_cons (purpose, value, chain)
  1785.      tree purpose, value, chain;
  1786. {
  1787.   register tree node;
  1788.   register struct obstack *ambient_obstack = current_obstack;
  1789.   current_obstack = &temp_decl_obstack;
  1790.   node = tree_cons (purpose, value, chain);
  1791.   current_obstack = ambient_obstack;
  1792.   return node;
  1793. }
  1794.  
  1795. /* Same as `tree_cons' but make a permanent object.  */
  1796.  
  1797. tree
  1798. perm_tree_cons (purpose, value, chain)
  1799.      tree purpose, value, chain;
  1800. {
  1801.   register tree node;
  1802.   register struct obstack *ambient_obstack = current_obstack;
  1803.   current_obstack = &permanent_obstack;
  1804.  
  1805.   node = tree_cons (purpose, value, chain);
  1806.   current_obstack = ambient_obstack;
  1807.   return node;
  1808. }
  1809.  
  1810. /* Same as `tree_cons', but make this node temporary, regardless.  */
  1811.  
  1812. tree
  1813. temp_tree_cons (purpose, value, chain)
  1814.      tree purpose, value, chain;
  1815. {
  1816.   register tree node;
  1817.   register struct obstack *ambient_obstack = current_obstack;
  1818.   current_obstack = &temporary_obstack;
  1819.  
  1820.   node = tree_cons (purpose, value, chain);
  1821.   current_obstack = ambient_obstack;
  1822.   return node;
  1823. }
  1824.  
  1825. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  1826.  
  1827. tree
  1828. saveable_tree_cons (purpose, value, chain)
  1829.      tree purpose, value, chain;
  1830. {
  1831.   register tree node;
  1832.   register struct obstack *ambient_obstack = current_obstack;
  1833.   current_obstack = saveable_obstack;
  1834.  
  1835.   node = tree_cons (purpose, value, chain);
  1836.   current_obstack = ambient_obstack;
  1837.   return node;
  1838. }
  1839.  
  1840. /* Return the size nominally occupied by an object of type TYPE
  1841.    when it resides in memory.  The value is measured in units of bytes,
  1842.    and its data type is that normally used for type sizes
  1843.    (which is the first type created by make_signed_type or
  1844.    make_unsigned_type).  */
  1845.  
  1846. tree
  1847. size_in_bytes (type)
  1848.      tree type;
  1849. {
  1850.   tree t;
  1851.  
  1852.   if (type == error_mark_node)
  1853.     return integer_zero_node;
  1854.   type = TYPE_MAIN_VARIANT (type);
  1855.   if (TYPE_SIZE (type) == 0)
  1856.     {
  1857.       incomplete_type_error (NULL_TREE, type);
  1858.       return integer_zero_node;
  1859.     }
  1860.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1861.           size_int (BITS_PER_UNIT));
  1862.   if (TREE_CODE (t) == INTEGER_CST)
  1863.     force_fit_type (t, 0);
  1864.   return t;
  1865. }
  1866.  
  1867. /* Return the size of TYPE (in bytes) as an integer,
  1868.    or return -1 if the size can vary.  */
  1869.  
  1870. int
  1871. int_size_in_bytes (type)
  1872.      tree type;
  1873. {
  1874.   unsigned int size;
  1875.   if (type == error_mark_node)
  1876.     return 0;
  1877.   type = TYPE_MAIN_VARIANT (type);
  1878.   if (TYPE_SIZE (type) == 0)
  1879.     return -1;
  1880.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  1881.     return -1;
  1882.   if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
  1883.     {
  1884.       tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1885.                size_int (BITS_PER_UNIT));
  1886.       return TREE_INT_CST_LOW (t);
  1887.     }
  1888.   size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  1889.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  1890. }
  1891.  
  1892. /* Return, as a tree node, the number of elements for TYPE (which is an
  1893.    ARRAY_TYPE) minus one. This counts only elements of the top array.  */
  1894.  
  1895. tree
  1896. array_type_nelts (type)
  1897.      tree type;
  1898. {
  1899.   tree index_type = TYPE_DOMAIN (type);
  1900.  
  1901.   return (integer_zerop (TYPE_MIN_VALUE (index_type))
  1902.       ? TYPE_MAX_VALUE (index_type)
  1903.       : fold (build (MINUS_EXPR, TREE_TYPE (TYPE_MAX_VALUE (index_type)),
  1904.              TYPE_MAX_VALUE (index_type),
  1905.              TYPE_MIN_VALUE (index_type))));
  1906. }
  1907.  
  1908. /* Return nonzero if arg is static -- a reference to an object in
  1909.    static storage.  This is not the same as the C meaning of `static'.  */
  1910.  
  1911. int
  1912. staticp (arg)
  1913.      tree arg;
  1914. {
  1915.   switch (TREE_CODE (arg))
  1916.     {
  1917.     case FUNCTION_DECL:
  1918.       /* Nested functions aren't static, since taking their address
  1919.      involves a trampoline.  */
  1920.        return decl_function_context (arg) == 0;
  1921.     case VAR_DECL:
  1922.       return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
  1923.  
  1924.     case CONSTRUCTOR:
  1925.       return TREE_STATIC (arg);
  1926.  
  1927.     case STRING_CST:
  1928.       return 1;
  1929.  
  1930.     case COMPONENT_REF:
  1931.     case BIT_FIELD_REF:
  1932.       return staticp (TREE_OPERAND (arg, 0));
  1933.  
  1934.     case INDIRECT_REF:
  1935.       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
  1936.  
  1937.     case ARRAY_REF:
  1938.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  1939.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  1940.     return staticp (TREE_OPERAND (arg, 0));
  1941.     }
  1942.  
  1943.   return 0;
  1944. }
  1945.  
  1946. /* Wrap a SAVE_EXPR around EXPR, if appropriate.
  1947.    Do this to any expression which may be used in more than one place,
  1948.    but must be evaluated only once.
  1949.  
  1950.    Normally, expand_expr would reevaluate the expression each time.
  1951.    Calling save_expr produces something that is evaluated and recorded
  1952.    the first time expand_expr is called on it.  Subsequent calls to
  1953.    expand_expr just reuse the recorded value.
  1954.  
  1955.    The call to expand_expr that generates code that actually computes
  1956.    the value is the first call *at compile time*.  Subsequent calls
  1957.    *at compile time* generate code to use the saved value.
  1958.    This produces correct result provided that *at run time* control
  1959.    always flows through the insns made by the first expand_expr
  1960.    before reaching the other places where the save_expr was evaluated.
  1961.    You, the caller of save_expr, must make sure this is so.
  1962.  
  1963.    Constants, and certain read-only nodes, are returned with no
  1964.    SAVE_EXPR because that is safe.  Expressions containing placeholders
  1965.    are not touched; see tree.def for an explanation of what these
  1966.    are used for.  */
  1967.  
  1968. tree
  1969. save_expr (expr)
  1970.      tree expr;
  1971. {
  1972.   register tree t = fold (expr);
  1973.  
  1974.   /* We don't care about whether this can be used as an lvalue in this
  1975.      context.  */
  1976.   while (TREE_CODE (t) == NON_LVALUE_EXPR)
  1977.     t = TREE_OPERAND (t, 0);
  1978.  
  1979.   /* If the tree evaluates to a constant, then we don't want to hide that
  1980.      fact (i.e. this allows further folding, and direct checks for constants).
  1981.      However, a read-only object that has side effects cannot be bypassed.
  1982.      Since it is no problem to reevaluate literals, we just return the 
  1983.      literal node. */
  1984.  
  1985.   if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
  1986.       || TREE_CODE (t) == SAVE_EXPR)
  1987.     return t;
  1988.  
  1989.   /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
  1990.      it means that the size or offset of some field of an object depends on
  1991.      the value within another field.
  1992.  
  1993.      Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
  1994.      and some variable since it would then need to be both evaluated once and
  1995.      evaluated more than once.  Front-ends must assure this case cannot
  1996.      happen by surrounding any such subexpressions in their own SAVE_EXPR
  1997.      and forcing evaluation at the proper time.  */
  1998.   if (contains_placeholder_p (t))
  1999.     return t;
  2000.  
  2001.   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
  2002.  
  2003.   /* This expression might be placed ahead of a jump to ensure that the
  2004.      value was computed on both sides of the jump.  So make sure it isn't
  2005.      eliminated as dead.  */
  2006.   TREE_SIDE_EFFECTS (t) = 1;
  2007.   return t;
  2008. }
  2009.  
  2010. /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
  2011.    or offset that depends on a field within a record.
  2012.  
  2013.    Note that we only allow such expressions within simple arithmetic
  2014.    or a COND_EXPR.  */
  2015.  
  2016. int
  2017. contains_placeholder_p (exp)
  2018.      tree exp;
  2019. {
  2020.   register enum tree_code code = TREE_CODE (exp);
  2021.   tree inner;
  2022.  
  2023.   /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
  2024.      in it since it is supplying a value for it.  */
  2025.   if (code == WITH_RECORD_EXPR)
  2026.     return 0;
  2027.  
  2028.   switch (TREE_CODE_CLASS (code))
  2029.     {
  2030.     case 'r':
  2031.       for (inner = TREE_OPERAND (exp, 0);
  2032.        TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2033.        inner = TREE_OPERAND (inner, 0))
  2034.     ;
  2035.       return TREE_CODE (inner) == PLACEHOLDER_EXPR;
  2036.  
  2037.     case '1':
  2038.     case '2':  case '<':
  2039.     case 'e':
  2040.       switch (tree_code_length[(int) code])
  2041.     {
  2042.     case 1:
  2043.       return contains_placeholder_p (TREE_OPERAND (exp, 0));
  2044.     case 2:
  2045.       return (code != RTL_EXPR
  2046.           && code != CONSTRUCTOR
  2047.           && ! (code == SAVE_EXPR && SAVE_EXPR_RTL (exp) != 0)
  2048.           && code != WITH_RECORD_EXPR
  2049.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2050.               || contains_placeholder_p (TREE_OPERAND (exp, 1))));
  2051.     case 3:
  2052.       return (code == COND_EXPR
  2053.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2054.               || contains_placeholder_p (TREE_OPERAND (exp, 1))
  2055.               || contains_placeholder_p (TREE_OPERAND (exp, 2))));
  2056.     }
  2057.     }
  2058.  
  2059.   return 0;
  2060. }
  2061.  
  2062. /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
  2063.    return a tree with all occurrences of references to F in a
  2064.    PLACEHOLDER_EXPR replaced by R.   Note that we assume here that EXP
  2065.    contains only arithmetic expressions.  */
  2066.  
  2067. tree
  2068. substitute_in_expr (exp, f, r)
  2069.      tree exp;
  2070.      tree f;
  2071.      tree r;
  2072. {
  2073.   enum tree_code code = TREE_CODE (exp);
  2074.   tree inner;
  2075.  
  2076.   switch (TREE_CODE_CLASS (code))
  2077.     {
  2078.     case 'c':
  2079.     case 'd':
  2080.       return exp;
  2081.  
  2082.     case 'x':
  2083.       if (code == PLACEHOLDER_EXPR)
  2084.     return exp;
  2085.       break;
  2086.  
  2087.     case '1':
  2088.     case '2':
  2089.     case '<':
  2090.     case 'e':
  2091.       switch (tree_code_length[(int) code])
  2092.     {
  2093.     case 1:
  2094.       return fold (build1 (code, TREE_TYPE (exp),
  2095.                    substitute_in_expr (TREE_OPERAND (exp, 0),
  2096.                            f, r)));
  2097.  
  2098.     case 2:
  2099.       /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
  2100.          could, but we don't support it.  */
  2101.       if (code == RTL_EXPR)
  2102.         return exp;
  2103.       else if (code == CONSTRUCTOR)
  2104.         abort ();
  2105.  
  2106.       return fold (build (code, TREE_TYPE (exp),
  2107.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2108.                   substitute_in_expr (TREE_OPERAND (exp, 1),
  2109.                           f, r)));
  2110.  
  2111.     case 3:
  2112.       /* It cannot be that anything inside a SAVE_EXPR contains a
  2113.          PLACEHOLDER_EXPR.  */
  2114.       if (code == SAVE_EXPR)
  2115.         return exp;
  2116.  
  2117.       if (code != COND_EXPR)
  2118.         abort ();
  2119.  
  2120.       return fold (build (code, TREE_TYPE (exp),
  2121.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2122.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2123.                   substitute_in_expr (TREE_OPERAND (exp, 2),
  2124.                           f, r)));
  2125.     }
  2126.  
  2127.       break;
  2128.  
  2129.     case 'r':
  2130.       switch (code)
  2131.     {
  2132.     case COMPONENT_REF:
  2133.       /* If this expression is getting a value from a PLACEHOLDER_EXPR
  2134.          and it is the right field, replace it with R.  */
  2135.       for (inner = TREE_OPERAND (exp, 0);
  2136.            TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2137.            inner = TREE_OPERAND (inner, 0))
  2138.         ;
  2139.       if (TREE_CODE (inner) == PLACEHOLDER_EXPR
  2140.           && TREE_OPERAND (exp, 1) == f)
  2141.         return r;
  2142.  
  2143.       return fold (build (code, TREE_TYPE (exp),
  2144.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2145.                   TREE_OPERAND (exp, 1)));
  2146.     case BIT_FIELD_REF:
  2147.       return fold (build (code, TREE_TYPE (exp),
  2148.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2149.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2150.                   substitute_in_expr (TREE_OPERAND (exp, 2), f, r)));
  2151.     case INDIRECT_REF:
  2152.     case BUFFER_REF:
  2153.       return fold (build1 (code, TREE_TYPE (exp),
  2154.                    substitute_in_expr (TREE_OPERAND (exp, 0),
  2155.                          f, r)));
  2156.     case OFFSET_REF:
  2157.       return fold (build (code, TREE_TYPE (exp),
  2158.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2159.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r)));
  2160.     }
  2161.     }
  2162.  
  2163.   /* If it wasn't one of the cases we handle, give up.  */
  2164.  
  2165.   abort ();
  2166. }
  2167.  
  2168. /* Given a type T, a FIELD_DECL F, and a replacement value R,
  2169.    return a new type with all size expressions that contain F
  2170.    updated by replacing F with R.  */
  2171.  
  2172. tree
  2173. substitute_in_type (t, f, r)
  2174.      tree t, f, r;
  2175. {
  2176.   switch (TREE_CODE (t))
  2177.     {
  2178.     case POINTER_TYPE:
  2179.     case VOID_TYPE:
  2180.       return t;
  2181.     case INTEGER_TYPE:
  2182.     case ENUMERAL_TYPE:
  2183.     case BOOLEAN_TYPE:
  2184.     case CHAR_TYPE:
  2185.       if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
  2186.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2187.       || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
  2188.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2189.     return build_range_type (t,
  2190.                  substitute_in_expr (TYPE_MIN_VALUE (t), f, r),
  2191.                  substitute_in_expr (TYPE_MAX_VALUE (t), f, r));
  2192.       return t;
  2193.  
  2194.     case REAL_TYPE:
  2195.       if ((TYPE_MIN_VALUE (t) != 0
  2196.        && TREE_CODE (TYPE_MIN_VALUE (t)) != REAL_CST
  2197.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2198.       || (TYPE_MAX_VALUE (t) != 0
  2199.           && TREE_CODE (TYPE_MAX_VALUE (t)) != REAL_CST
  2200.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2201.     {
  2202.       t = build_type_copy (t);
  2203.  
  2204.       if (TYPE_MIN_VALUE (t))
  2205.         TYPE_MIN_VALUE (t) = substitute_in_expr (TYPE_MIN_VALUE (t), f, r);
  2206.       if (TYPE_MAX_VALUE (t))
  2207.         TYPE_MAX_VALUE (t) = substitute_in_expr (TYPE_MAX_VALUE (t), f, r);
  2208.     }
  2209.       return t;
  2210.  
  2211.     case COMPLEX_TYPE:
  2212.       return build_complex_type (substitute_in_type (TREE_TYPE (t), f, r));
  2213.  
  2214.     case OFFSET_TYPE:
  2215.     case METHOD_TYPE:
  2216.     case REFERENCE_TYPE:
  2217.     case FILE_TYPE:
  2218.     case SET_TYPE:
  2219.     case FUNCTION_TYPE:
  2220.     case LANG_TYPE:
  2221.       /* Don't know how to do these yet.  */
  2222.       abort ();
  2223.  
  2224.     case ARRAY_TYPE:
  2225.       t = build_array_type (substitute_in_type (TREE_TYPE (t), f, r),
  2226.                 substitute_in_type (TYPE_DOMAIN (t), f, r));
  2227.       TYPE_SIZE (t) = 0;
  2228.       layout_type (t);
  2229.       return t;
  2230.  
  2231.     case RECORD_TYPE:
  2232.     case UNION_TYPE:
  2233.     case QUAL_UNION_TYPE:
  2234.       {
  2235.     tree new = copy_node (t);
  2236.     tree field;
  2237.     tree last_field = 0;
  2238.  
  2239.     /* Start out with no fields, make new fields, and chain them
  2240.        in.  */
  2241.  
  2242.     TYPE_FIELDS (new) = 0;
  2243.     TYPE_SIZE (new) = 0;
  2244.  
  2245.     for (field = TYPE_FIELDS (t); field;
  2246.          field = TREE_CHAIN (field))
  2247.       {
  2248.         tree new_field = copy_node (field);
  2249.  
  2250.         TREE_TYPE (new_field)
  2251.           = substitute_in_type (TREE_TYPE (new_field), f, r);
  2252.  
  2253.         /* If this is an anonymous field and the type of this field is
  2254.            a UNION_TYPE or RECORD_TYPE with no elements, ignore it.  If
  2255.            the type just has one element, treat that as the field. 
  2256.            But don't do this if we are processing a QUAL_UNION_TYPE.  */
  2257.         if (TREE_CODE (t) != QUAL_UNION_TYPE && DECL_NAME (new_field) == 0
  2258.         && (TREE_CODE (TREE_TYPE (new_field)) == UNION_TYPE
  2259.             || TREE_CODE (TREE_TYPE (new_field)) == RECORD_TYPE))
  2260.           {
  2261.         if (TYPE_FIELDS (TREE_TYPE (new_field)) == 0)
  2262.           continue;
  2263.  
  2264.         if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field))) == 0)
  2265.           new_field = TYPE_FIELDS (TREE_TYPE (new_field));
  2266.           }
  2267.  
  2268.         DECL_CONTEXT (new_field) = new;
  2269.         DECL_SIZE (new_field) = 0;
  2270.  
  2271.         if (TREE_CODE (t) == QUAL_UNION_TYPE)
  2272.           {
  2273.         /* Do the substitution inside the qualifier and if we find
  2274.            that this field will not be present, omit it.  */
  2275.         DECL_QUALIFIER (new_field)
  2276.           = substitute_in_expr (DECL_QUALIFIER (field), f, r);
  2277.         if (integer_zerop (DECL_QUALIFIER (new_field)))
  2278.           continue;
  2279.           }
  2280.  
  2281.         if (last_field == 0)
  2282.           TYPE_FIELDS (new) = new_field;
  2283.         else
  2284.           TREE_CHAIN (last_field) = new_field;
  2285.  
  2286.         last_field = new_field;
  2287.  
  2288.         /* If this is a qualified type and this field will always be
  2289.            present, we are done.  */
  2290.         if (TREE_CODE (t) == QUAL_UNION_TYPE
  2291.         && integer_onep (DECL_QUALIFIER (new_field)))
  2292.           break;
  2293.       }
  2294.  
  2295.     /* If this used to be a qualified union type, but we now know what
  2296.        field will be present, make this a normal union.  */
  2297.     if (TREE_CODE (new) == QUAL_UNION_TYPE
  2298.         && (TYPE_FIELDS (new) == 0
  2299.         || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
  2300.       TREE_SET_CODE (new, UNION_TYPE);
  2301.  
  2302.     layout_type (new);
  2303.     return new;
  2304.       }
  2305.     }
  2306. }
  2307.  
  2308. /* Stabilize a reference so that we can use it any number of times
  2309.    without causing its operands to be evaluated more than once.
  2310.    Returns the stabilized reference.  This works by means of save_expr,
  2311.    so see the caveats in the comments about save_expr.
  2312.  
  2313.    Also allows conversion expressions whose operands are references.
  2314.    Any other kind of expression is returned unchanged.  */
  2315.  
  2316. tree
  2317. stabilize_reference (ref)
  2318.      tree ref;
  2319. {
  2320.   register tree result;
  2321.   register enum tree_code code = TREE_CODE (ref);
  2322.  
  2323.   switch (code)
  2324.     {
  2325.     case VAR_DECL:
  2326.     case PARM_DECL:
  2327.     case RESULT_DECL:
  2328.       /* No action is needed in this case.  */
  2329.       return ref;
  2330.  
  2331.     case NOP_EXPR:
  2332.     case CONVERT_EXPR:
  2333.     case FLOAT_EXPR:
  2334.     case FIX_TRUNC_EXPR:
  2335.     case FIX_FLOOR_EXPR:
  2336.     case FIX_ROUND_EXPR:
  2337.     case FIX_CEIL_EXPR:
  2338.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  2339.       break;
  2340.  
  2341.     case INDIRECT_REF:
  2342.       result = build_nt (INDIRECT_REF,
  2343.              stabilize_reference_1 (TREE_OPERAND (ref, 0)));
  2344.       break;
  2345.  
  2346.     case COMPONENT_REF:
  2347.       result = build_nt (COMPONENT_REF,
  2348.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2349.              TREE_OPERAND (ref, 1));
  2350.       break;
  2351.  
  2352.     case BIT_FIELD_REF:
  2353.       result = build_nt (BIT_FIELD_REF,
  2354.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2355.              stabilize_reference_1 (TREE_OPERAND (ref, 1)),
  2356.              stabilize_reference_1 (TREE_OPERAND (ref, 2)));
  2357.       break;
  2358.  
  2359.     case ARRAY_REF:
  2360.       result = build_nt (ARRAY_REF,
  2361.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2362.              stabilize_reference_1 (TREE_OPERAND (ref, 1)));
  2363.       break;
  2364.  
  2365.     case COMPOUND_EXPR:
  2366.       result = build_nt (COMPOUND_EXPR,
  2367.              stabilize_reference_1 (TREE_OPERAND (ref, 0)),
  2368.              stabilize_reference (TREE_OPERAND (ref, 1)));
  2369.       break;
  2370.  
  2371.  
  2372.       /* If arg isn't a kind of lvalue we recognize, make no change.
  2373.      Caller should recognize the error for an invalid lvalue.  */
  2374.     default:
  2375.       return ref;
  2376.  
  2377.     case ERROR_MARK:
  2378.       return error_mark_node;
  2379.     }
  2380.  
  2381.   TREE_TYPE (result) = TREE_TYPE (ref);
  2382.   TREE_READONLY (result) = TREE_READONLY (ref);
  2383.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
  2384.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  2385.   TREE_RAISES (result) = TREE_RAISES (ref);
  2386.  
  2387.   return result;
  2388. }
  2389.  
  2390. /* Subroutine of stabilize_reference; this is called for subtrees of
  2391.    references.  Any expression with side-effects must be put in a SAVE_EXPR
  2392.    to ensure that it is only evaluated once.
  2393.  
  2394.    We don't put SAVE_EXPR nodes around everything, because assigning very
  2395.    simple expressions to temporaries causes us to miss good opportunities
  2396.    for optimizations.  Among other things, the opportunity to fold in the
  2397.    addition of a constant into an addressing mode often gets lost, e.g.
  2398.    "y[i+1] += x;".  In general, we take the approach that we should not make
  2399.    an assignment unless we are forced into it - i.e., that any non-side effect
  2400.    operator should be allowed, and that cse should take care of coalescing
  2401.    multiple utterances of the same expression should that prove fruitful.  */
  2402.  
  2403. static tree
  2404. stabilize_reference_1 (e)
  2405.      tree e;
  2406. {
  2407.   register tree result;
  2408.   register enum tree_code code = TREE_CODE (e);
  2409.  
  2410.   /* We cannot ignore const expressions because it might be a reference
  2411.      to a const array but whose index contains side-effects.  But we can
  2412.      ignore things that are actual constant or that already have been
  2413.      handled by this function.  */
  2414.  
  2415.   if (TREE_CONSTANT (e) || code == SAVE_EXPR)
  2416.     return e;
  2417.  
  2418.   switch (TREE_CODE_CLASS (code))
  2419.     {
  2420.     case 'x':
  2421.     case 't':
  2422.     case 'd':
  2423.     case 'b':
  2424.     case '<':
  2425.     case 's':
  2426.     case 'e':
  2427.     case 'r':
  2428.       /* If the expression has side-effects, then encase it in a SAVE_EXPR
  2429.      so that it will only be evaluated once.  */
  2430.       /* The reference (r) and comparison (<) classes could be handled as
  2431.      below, but it is generally faster to only evaluate them once.  */
  2432.       if (TREE_SIDE_EFFECTS (e))
  2433.     return save_expr (e);
  2434.       return e;
  2435.  
  2436.     case 'c':
  2437.       /* Constants need no processing.  In fact, we should never reach
  2438.      here.  */
  2439.       return e;
  2440.       
  2441.     case '2':
  2442.       /* Division is slow and tends to be compiled with jumps,
  2443.      especially the division by powers of 2 that is often
  2444.      found inside of an array reference.  So do it just once.  */
  2445.       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
  2446.       || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
  2447.       || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
  2448.       || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
  2449.     return save_expr (e);
  2450.       /* Recursively stabilize each operand.  */
  2451.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
  2452.              stabilize_reference_1 (TREE_OPERAND (e, 1)));
  2453.       break;
  2454.  
  2455.     case '1':
  2456.       /* Recursively stabilize each operand.  */
  2457.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
  2458.       break;
  2459.  
  2460.     default:
  2461.       abort ();
  2462.     }
  2463.   
  2464.   TREE_TYPE (result) = TREE_TYPE (e);
  2465.   TREE_READONLY (result) = TREE_READONLY (e);
  2466.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
  2467.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
  2468.   TREE_RAISES (result) = TREE_RAISES (e);
  2469.  
  2470.   return result;
  2471. }
  2472.  
  2473. /* Low-level constructors for expressions.  */
  2474.  
  2475. /* Build an expression of code CODE, data type TYPE,
  2476.    and operands as specified by the arguments ARG1 and following arguments.
  2477.    Expressions and reference nodes can be created this way.
  2478.    Constants, decls, types and misc nodes cannot be.  */
  2479.  
  2480. tree
  2481. build VPROTO((enum tree_code code, tree tt, ...))
  2482. {
  2483. #ifndef __STDC__
  2484.   enum tree_code code;
  2485.   tree tt;
  2486. #endif
  2487.   va_list p;
  2488.   register tree t;
  2489.   register int length;
  2490.   register int i;
  2491.  
  2492.   VA_START (p, tt);
  2493.  
  2494. #ifndef __STDC__
  2495.   code = va_arg (p, enum tree_code);
  2496.   tt = va_arg (p, tree);
  2497. #endif
  2498.  
  2499.   t = make_node (code);
  2500.   length = tree_code_length[(int) code];
  2501.   TREE_TYPE (t) = tt;
  2502.  
  2503.   if (length == 2)
  2504.     {
  2505.       /* This is equivalent to the loop below, but faster.  */
  2506.       register tree arg0 = va_arg (p, tree);
  2507.       register tree arg1 = va_arg (p, tree);
  2508.       TREE_OPERAND (t, 0) = arg0;
  2509.       TREE_OPERAND (t, 1) = arg1;
  2510.       if ((arg0 && TREE_SIDE_EFFECTS (arg0))
  2511.       || (arg1 && TREE_SIDE_EFFECTS (arg1)))
  2512.     TREE_SIDE_EFFECTS (t) = 1;
  2513.       TREE_RAISES (t)
  2514.     = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
  2515.     }
  2516.   else if (length == 1)
  2517.     {
  2518.       register tree arg0 = va_arg (p, tree);
  2519.  
  2520.       /* Call build1 for this!  */
  2521.       if (TREE_CODE_CLASS (code) != 's')
  2522.     abort ();
  2523.       TREE_OPERAND (t, 0) = arg0;
  2524.       if (arg0 && TREE_SIDE_EFFECTS (arg0))
  2525.     TREE_SIDE_EFFECTS (t) = 1;
  2526.       TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
  2527.     }
  2528.   else
  2529.     {
  2530.       for (i = 0; i < length; i++)
  2531.     {
  2532.       register tree operand = va_arg (p, tree);
  2533.       TREE_OPERAND (t, i) = operand;
  2534.       if (operand)
  2535.         {
  2536.           if (TREE_SIDE_EFFECTS (operand))
  2537.         TREE_SIDE_EFFECTS (t) = 1;
  2538.           if (TREE_RAISES (operand))
  2539.         TREE_RAISES (t) = 1;
  2540.         }
  2541.     }
  2542.     }
  2543.   va_end (p);
  2544.   return t;
  2545. }
  2546.  
  2547. /* Same as above, but only builds for unary operators.
  2548.    Saves lions share of calls to `build'; cuts down use
  2549.    of varargs, which is expensive for RISC machines.  */
  2550. tree
  2551. build1 (code, type, node)
  2552.      enum tree_code code;
  2553.      tree type;
  2554.      tree node;
  2555. {
  2556.   register struct obstack *obstack = current_obstack;
  2557.   register int i, length;
  2558.   register tree_node_kind kind;
  2559.   register tree t;
  2560.  
  2561. #ifdef GATHER_STATISTICS
  2562.   if (TREE_CODE_CLASS (code) == 'r')
  2563.     kind = r_kind;
  2564.   else
  2565.     kind = e_kind;
  2566. #endif
  2567.  
  2568.   obstack = expression_obstack;
  2569.   length = sizeof (struct tree_exp);
  2570.  
  2571.   t = (tree) obstack_alloc (obstack, length);
  2572.  
  2573. #ifdef GATHER_STATISTICS
  2574.   tree_node_counts[(int)kind]++;
  2575.   tree_node_sizes[(int)kind] += length;
  2576. #endif
  2577.  
  2578.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  2579.     ((int *) t)[i] = 0;
  2580.  
  2581.   TREE_TYPE (t) = type;
  2582.   TREE_SET_CODE (t, code);
  2583.  
  2584.   if (obstack == &permanent_obstack)
  2585.     TREE_PERMANENT (t) = 1;
  2586.  
  2587.   TREE_OPERAND (t, 0) = node;
  2588.   if (node)
  2589.     {
  2590.       if (TREE_SIDE_EFFECTS (node))
  2591.     TREE_SIDE_EFFECTS (t) = 1;
  2592.       if (TREE_RAISES (node))
  2593.     TREE_RAISES (t) = 1;
  2594.     }
  2595.  
  2596.   return t;
  2597. }
  2598.  
  2599. /* Similar except don't specify the TREE_TYPE
  2600.    and leave the TREE_SIDE_EFFECTS as 0.
  2601.    It is permissible for arguments to be null,
  2602.    or even garbage if their values do not matter.  */
  2603.  
  2604. tree
  2605. build_nt VPROTO((enum tree_code code, ...))
  2606. {
  2607. #ifndef __STDC__
  2608.   enum tree_code code;
  2609. #endif
  2610.   va_list p;
  2611.   register tree t;
  2612.   register int length;
  2613.   register int i;
  2614.  
  2615.   VA_START (p, code);
  2616.  
  2617. #ifndef __STDC__
  2618.   code = va_arg (p, enum tree_code);
  2619. #endif
  2620.  
  2621.   t = make_node (code);
  2622.   length = tree_code_length[(int) code];
  2623.  
  2624.   for (i = 0; i < length; i++)
  2625.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2626.  
  2627.   va_end (p);
  2628.   return t;
  2629. }
  2630.  
  2631. /* Similar to `build_nt', except we build
  2632.    on the temp_decl_obstack, regardless.  */
  2633.  
  2634. tree
  2635. build_parse_node VPROTO((enum tree_code code, ...))
  2636. {
  2637. #ifndef __STDC__
  2638.   enum tree_code code;
  2639. #endif
  2640.   register struct obstack *ambient_obstack = expression_obstack;
  2641.   va_list p;
  2642.   register tree t;
  2643.   register int length;
  2644.   register int i;
  2645.  
  2646.   VA_START (p, code);
  2647.  
  2648. #ifndef __STDC__
  2649.   code = va_arg (p, enum tree_code);
  2650. #endif
  2651.  
  2652.   expression_obstack = &temp_decl_obstack;
  2653.  
  2654.   t = make_node (code);
  2655.   length = tree_code_length[(int) code];
  2656.  
  2657.   for (i = 0; i < length; i++)
  2658.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2659.  
  2660.   va_end (p);
  2661.   expression_obstack = ambient_obstack;
  2662.   return t;
  2663. }
  2664.  
  2665. #if 0
  2666. /* Commented out because this wants to be done very
  2667.    differently.  See cp-lex.c.  */
  2668. tree
  2669. build_op_identifier (op1, op2)
  2670.      tree op1, op2;
  2671. {
  2672.   register tree t = make_node (OP_IDENTIFIER);
  2673.   TREE_PURPOSE (t) = op1;
  2674.   TREE_VALUE (t) = op2;
  2675.   return t;
  2676. }
  2677. #endif
  2678.  
  2679. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  2680.    We do NOT enter this node in any sort of symbol table.
  2681.  
  2682.    layout_decl is used to set up the decl's storage layout.
  2683.    Other slots are initialized to 0 or null pointers.  */
  2684.  
  2685. tree
  2686. build_decl (code, name, type)
  2687.      enum tree_code code;
  2688.      tree name, type;
  2689. {
  2690.   register tree t;
  2691.  
  2692.   t = make_node (code);
  2693.  
  2694. /*  if (type == error_mark_node)
  2695.     type = integer_type_node; */
  2696. /* That is not done, deliberately, so that having error_mark_node
  2697.    as the type can suppress useless errors in the use of this variable.  */
  2698.  
  2699.   DECL_NAME (t) = name;
  2700.   DECL_ASSEMBLER_NAME (t) = name;
  2701.   TREE_TYPE (t) = type;
  2702.  
  2703.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  2704.     layout_decl (t, 0);
  2705.   else if (code == FUNCTION_DECL)
  2706.     DECL_MODE (t) = FUNCTION_MODE;
  2707.  
  2708.   return t;
  2709. }
  2710.  
  2711. /* BLOCK nodes are used to represent the structure of binding contours
  2712.    and declarations, once those contours have been exited and their contents
  2713.    compiled.  This information is used for outputting debugging info.  */
  2714.  
  2715. tree
  2716. build_block (vars, tags, subblocks, supercontext, chain)
  2717.      tree vars, tags, subblocks, supercontext, chain;
  2718. {
  2719.   register tree block = make_node (BLOCK);
  2720.   BLOCK_VARS (block) = vars;
  2721.   BLOCK_TYPE_TAGS (block) = tags;
  2722.   BLOCK_SUBBLOCKS (block) = subblocks;
  2723.   BLOCK_SUPERCONTEXT (block) = supercontext;
  2724.   BLOCK_CHAIN (block) = chain;
  2725.   return block;
  2726. }
  2727.  
  2728. /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
  2729.    is ATTRIBUTE.
  2730.  
  2731.    Such modified types already made are recorded so that duplicates
  2732.    are not made. */
  2733.  
  2734. tree
  2735. build_type_attribute_variant (ttype, attribute)
  2736.      tree ttype, attribute;
  2737. {
  2738.   if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
  2739.     {
  2740.       register int hashcode;
  2741.       register struct obstack *ambient_obstack = current_obstack;
  2742.       tree ntype;
  2743.  
  2744.       if (ambient_obstack != &permanent_obstack)
  2745.         current_obstack = TYPE_OBSTACK (ttype);
  2746.  
  2747.       ntype = copy_node (ttype);
  2748.       current_obstack = ambient_obstack;
  2749.  
  2750.       TYPE_POINTER_TO (ntype) = 0;
  2751.       TYPE_REFERENCE_TO (ntype) = 0;
  2752.       TYPE_ATTRIBUTES (ntype) = attribute;
  2753.  
  2754.       /* Create a new main variant of TYPE.  */
  2755.       TYPE_MAIN_VARIANT (ntype) = ntype;
  2756.       TYPE_NEXT_VARIANT (ntype) = 0;
  2757.       TYPE_READONLY (ntype) = TYPE_VOLATILE (ntype) = 0;
  2758.  
  2759.       hashcode = TYPE_HASH (TREE_CODE (ntype))
  2760.          + TYPE_HASH (TREE_TYPE (ntype))
  2761.          + type_hash_list (attribute);
  2762.  
  2763.       switch (TREE_CODE (ntype))
  2764.         {
  2765.       case FUNCTION_TYPE:
  2766.         hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
  2767.         break;
  2768.       case ARRAY_TYPE:
  2769.         hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
  2770.         break;
  2771.       case INTEGER_TYPE:
  2772.         hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
  2773.         break;
  2774.       case REAL_TYPE:
  2775.         hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
  2776.         break;
  2777.         }
  2778.  
  2779.       ntype = type_hash_canon (hashcode, ntype);
  2780.       ttype = build_type_variant (ntype, TYPE_READONLY (ttype),
  2781.                   TYPE_VOLATILE (ttype));
  2782.     }
  2783.  
  2784.   return ttype;
  2785. }
  2786.  
  2787. /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
  2788.    and its TYPE_VOLATILE is VOLATILEP.
  2789.  
  2790.    Such variant types already made are recorded so that duplicates
  2791.    are not made.
  2792.  
  2793.    A variant types should never be used as the type of an expression.
  2794.    Always copy the variant information into the TREE_READONLY
  2795.    and TREE_THIS_VOLATILE of the expression, and then give the expression
  2796.    as its type the "main variant", the variant whose TYPE_READONLY
  2797.    and TYPE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  2798.    main variant.  */
  2799.  
  2800. tree
  2801. build_type_variant (type, constp, volatilep)
  2802.      tree type;
  2803.      int constp, volatilep;
  2804. {
  2805.   register tree t;
  2806.  
  2807.   /* Treat any nonzero argument as 1.  */
  2808.   constp = !!constp;
  2809.   volatilep = !!volatilep;
  2810.  
  2811.   /* Search the chain of variants to see if there is already one there just
  2812.      like the one we need to have.  If so, use that existing one.  We must
  2813.      preserve the TYPE_NAME, since there is code that depends on this.  */
  2814.  
  2815.   for (t = TYPE_MAIN_VARIANT(type); t; t = TYPE_NEXT_VARIANT (t))
  2816.     if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t)
  2817.     && TYPE_NAME (t) == TYPE_NAME (type))
  2818.       return t;
  2819.  
  2820.   /* We need a new one.  */
  2821.  
  2822.   t = build_type_copy (type);
  2823.   TYPE_READONLY (t) = constp;
  2824.   TYPE_VOLATILE (t) = volatilep;
  2825.  
  2826.   return t;
  2827. }
  2828.  
  2829. /* Give TYPE a new main variant: NEW_MAIN.
  2830.    This is the right thing to do only when something else
  2831.    about TYPE is modified in place.  */
  2832.  
  2833. void
  2834. change_main_variant (type, new_main)
  2835.      tree type, new_main;
  2836. {
  2837.   tree t;
  2838.   tree omain = TYPE_MAIN_VARIANT (type);
  2839.  
  2840.   /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant.  */
  2841.   if (TYPE_NEXT_VARIANT (omain) == type)
  2842.     TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
  2843.   else
  2844.     for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
  2845.      t = TYPE_NEXT_VARIANT (t))
  2846.       if (TYPE_NEXT_VARIANT (t) == type)
  2847.     {
  2848.       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
  2849.       break;
  2850.     }
  2851.  
  2852.   TYPE_MAIN_VARIANT (type) = new_main;
  2853.   TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
  2854.   TYPE_NEXT_VARIANT (new_main) = type;
  2855. }
  2856.  
  2857. /* Create a new variant of TYPE, equivalent but distinct.
  2858.    This is so the caller can modify it.  */
  2859.  
  2860. tree
  2861. build_type_copy (type)
  2862.      tree type;
  2863. {
  2864.   register tree t, m = TYPE_MAIN_VARIANT (type);
  2865.   register struct obstack *ambient_obstack = current_obstack;
  2866.  
  2867.   current_obstack = TYPE_OBSTACK (type);
  2868.   t = copy_node (type);
  2869.   current_obstack = ambient_obstack;
  2870.  
  2871.   TYPE_POINTER_TO (t) = 0;
  2872.   TYPE_REFERENCE_TO (t) = 0;
  2873.  
  2874.   /* Add this type to the chain of variants of TYPE.  */
  2875.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  2876.   TYPE_NEXT_VARIANT (m) = t;
  2877.  
  2878.   return t;
  2879. }
  2880.  
  2881. /* Hashing of types so that we don't make duplicates.
  2882.    The entry point is `type_hash_canon'.  */
  2883.  
  2884. /* Each hash table slot is a bucket containing a chain
  2885.    of these structures.  */
  2886.  
  2887. struct type_hash
  2888. {
  2889.   struct type_hash *next;    /* Next structure in the bucket.  */
  2890.   int hashcode;            /* Hash code of this type.  */
  2891.   tree type;            /* The type recorded here.  */
  2892. };
  2893.  
  2894. /* Now here is the hash table.  When recording a type, it is added
  2895.    to the slot whose index is the hash code mod the table size.
  2896.    Note that the hash table is used for several kinds of types
  2897.    (function types, array types and array index range types, for now).
  2898.    While all these live in the same table, they are completely independent,
  2899.    and the hash code is computed differently for each of these.  */
  2900.  
  2901. #define TYPE_HASH_SIZE 59
  2902. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  2903.  
  2904. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  2905.    with types in the TREE_VALUE slots), by adding the hash codes
  2906.    of the individual types.  */
  2907.  
  2908. int
  2909. type_hash_list (list)
  2910.      tree list;
  2911. {
  2912.   register int hashcode;
  2913.   register tree tail;
  2914.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  2915.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  2916.   return hashcode;
  2917. }
  2918.  
  2919. /* Look in the type hash table for a type isomorphic to TYPE.
  2920.    If one is found, return it.  Otherwise return 0.  */
  2921.  
  2922. tree
  2923. type_hash_lookup (hashcode, type)
  2924.      int hashcode;
  2925.      tree type;
  2926. {
  2927.   register struct type_hash *h;
  2928.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  2929.     if (h->hashcode == hashcode
  2930.     && TREE_CODE (h->type) == TREE_CODE (type)
  2931.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  2932.         && attribute_list_equal (TYPE_ATTRIBUTES (h->type),
  2933.                    TYPE_ATTRIBUTES (type))
  2934.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  2935.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  2936.                    TYPE_MAX_VALUE (type)))
  2937.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  2938.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  2939.                    TYPE_MIN_VALUE (type)))
  2940.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  2941.         || (TYPE_DOMAIN (h->type)
  2942.         && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  2943.         && TYPE_DOMAIN (type)
  2944.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  2945.         && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
  2946.       return h->type;
  2947.   return 0;
  2948. }
  2949.  
  2950. /* Add an entry to the type-hash-table
  2951.    for a type TYPE whose hash code is HASHCODE.  */
  2952.  
  2953. void
  2954. type_hash_add (hashcode, type)
  2955.      int hashcode;
  2956.      tree type;
  2957. {
  2958.   register struct type_hash *h;
  2959.  
  2960.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  2961.   h->hashcode = hashcode;
  2962.   h->type = type;
  2963.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  2964.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  2965. }
  2966.  
  2967. /* Given TYPE, and HASHCODE its hash code, return the canonical
  2968.    object for an identical type if one already exists.
  2969.    Otherwise, return TYPE, and record it as the canonical object
  2970.    if it is a permanent object.
  2971.  
  2972.    To use this function, first create a type of the sort you want.
  2973.    Then compute its hash code from the fields of the type that
  2974.    make it different from other similar types.
  2975.    Then call this function and use the value.
  2976.    This function frees the type you pass in if it is a duplicate.  */
  2977.  
  2978. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  2979. int debug_no_type_hash = 0;
  2980.  
  2981. tree
  2982. type_hash_canon (hashcode, type)
  2983.      int hashcode;
  2984.      tree type;
  2985. {
  2986.   tree t1;
  2987.  
  2988.   if (debug_no_type_hash)
  2989.     return type;
  2990.  
  2991.   t1 = type_hash_lookup (hashcode, type);
  2992.   if (t1 != 0)
  2993.     {
  2994.       obstack_free (TYPE_OBSTACK (type), type);
  2995. #ifdef GATHER_STATISTICS
  2996.       tree_node_counts[(int)t_kind]--;
  2997.       tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
  2998. #endif
  2999.       return t1;
  3000.     }
  3001.  
  3002.   /* If this is a permanent type, record it for later reuse.  */
  3003.   if (TREE_PERMANENT (type))
  3004.     type_hash_add (hashcode, type);
  3005.  
  3006.   return type;
  3007. }
  3008.  
  3009. /* Given two lists of attributes, return true if list l2 is
  3010.    equivalent to l1.  */
  3011.  
  3012. int
  3013. attribute_list_equal (l1, l2)
  3014.      tree l1, l2;
  3015. {
  3016.    return attribute_list_contained (l1, l2)
  3017.       && attribute_list_contained (l2, l1);
  3018. }
  3019.  
  3020. /* Given two lists of attributes, return true if list l2 is
  3021.    completely contained within l1.  */
  3022.  
  3023. int
  3024. attribute_list_contained (l1, l2)
  3025.      tree l1, l2;
  3026. {
  3027.   register tree t1, t2;
  3028.  
  3029.   /* First check the obvious, maybe the lists are identical.  */
  3030.   if (l1 == l2)
  3031.      return 1;
  3032.  
  3033.   /* Then check the obvious, maybe the lists are similar.  */
  3034.   for (t1 = l1, t2 = l2;
  3035.        t1 && t2
  3036.         && TREE_VALUE (t1) == TREE_VALUE (t2);
  3037.        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
  3038.  
  3039.   /* Maybe the lists are equal.  */
  3040.   if (t1 == 0 && t2 == 0)
  3041.      return 1;
  3042.  
  3043.   for (; t2; t2 = TREE_CHAIN (t2))
  3044.      if (!value_member (l1, t2))
  3045.     return 0;
  3046.   return 1;
  3047. }
  3048.  
  3049. /* Given two lists of types
  3050.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  3051.    return 1 if the lists contain the same types in the same order.
  3052.    Also, the TREE_PURPOSEs must match.  */
  3053.  
  3054. int
  3055. type_list_equal (l1, l2)
  3056.      tree l1, l2;
  3057. {
  3058.   register tree t1, t2;
  3059.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  3060.     {
  3061.       if (TREE_VALUE (t1) != TREE_VALUE (t2))
  3062.     return 0;
  3063.       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
  3064.     {
  3065.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  3066.       if (cmp < 0)
  3067.         abort ();
  3068.       if (cmp == 0
  3069.           || TREE_TYPE (TREE_PURPOSE (t1))
  3070.              != TREE_TYPE (TREE_PURPOSE (t2)))
  3071.         return 0;
  3072.     }
  3073.     }
  3074.  
  3075.   return t1 == t2;
  3076. }
  3077.  
  3078. /* Nonzero if integer constants T1 and T2
  3079.    represent the same constant value.  */
  3080.  
  3081. int
  3082. tree_int_cst_equal (t1, t2)
  3083.      tree t1, t2;
  3084. {
  3085.   if (t1 == t2)
  3086.     return 1;
  3087.   if (t1 == 0 || t2 == 0)
  3088.     return 0;
  3089.   if (TREE_CODE (t1) == INTEGER_CST
  3090.       && TREE_CODE (t2) == INTEGER_CST
  3091.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3092.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  3093.     return 1;
  3094.   return 0;
  3095. }
  3096.  
  3097. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  3098.    The precise way of comparison depends on their data type.  */
  3099.  
  3100. int
  3101. tree_int_cst_lt (t1, t2)
  3102.      tree t1, t2;
  3103. {
  3104.   if (t1 == t2)
  3105.     return 0;
  3106.  
  3107.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  3108.     return INT_CST_LT (t1, t2);
  3109.   return INT_CST_LT_UNSIGNED (t1, t2);
  3110. }
  3111.  
  3112. /* Return an indication of the sign of the integer constant T.
  3113.    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
  3114.    Note that -1 will never be returned it T's type is unsigned.  */
  3115.  
  3116. int
  3117. tree_int_cst_sgn (t)
  3118.      tree t;
  3119. {
  3120.   if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
  3121.     return 0;
  3122.   else if (TREE_UNSIGNED (TREE_TYPE (t)))
  3123.     return 1;
  3124.   else if (TREE_INT_CST_HIGH (t) < 0)
  3125.     return -1;
  3126.   else
  3127.     return 1;
  3128. }
  3129.  
  3130. /* Compare two constructor-element-type constants.  */
  3131. int
  3132. simple_cst_list_equal (l1, l2)
  3133.      tree l1, l2;
  3134. {
  3135.   while (l1 != NULL_TREE && l2 != NULL_TREE)
  3136.     {
  3137.       int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
  3138.       if (cmp < 0)
  3139.     abort ();
  3140.       if (cmp == 0)
  3141.     return 0;
  3142.       l1 = TREE_CHAIN (l1);
  3143.       l2 = TREE_CHAIN (l2);
  3144.     }
  3145.   return (l1 == l2);
  3146. }
  3147.  
  3148. /* Return truthvalue of whether T1 is the same tree structure as T2.
  3149.    Return 1 if they are the same.
  3150.    Return 0 if they are understandably different.
  3151.    Return -1 if either contains tree structure not understood by
  3152.    this function.  */
  3153.  
  3154. int
  3155. simple_cst_equal (t1, t2)
  3156.      tree t1, t2;
  3157. {
  3158.   register enum tree_code code1, code2;
  3159.   int cmp;
  3160.  
  3161.   if (t1 == t2)
  3162.     return 1;
  3163.   if (t1 == 0 || t2 == 0)
  3164.     return 0;
  3165.  
  3166.   code1 = TREE_CODE (t1);
  3167.   code2 = TREE_CODE (t2);
  3168.  
  3169.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
  3170.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
  3171.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3172.     else
  3173.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  3174.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
  3175.        || code2 == NON_LVALUE_EXPR)
  3176.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  3177.  
  3178.   if (code1 != code2)
  3179.     return 0;
  3180.  
  3181.   switch (code1)
  3182.     {
  3183.     case INTEGER_CST:
  3184.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3185.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  3186.  
  3187.     case REAL_CST:
  3188.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  3189.  
  3190.     case STRING_CST:
  3191.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  3192.     && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
  3193.           TREE_STRING_LENGTH (t1));
  3194.  
  3195.     case CONSTRUCTOR:
  3196.       abort ();
  3197.  
  3198.     case SAVE_EXPR:
  3199.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3200.  
  3201.     case CALL_EXPR:
  3202.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3203.       if (cmp <= 0)
  3204.     return cmp;
  3205.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3206.  
  3207.     case TARGET_EXPR:
  3208.       /* Special case: if either target is an unallocated VAR_DECL,
  3209.      it means that it's going to be unified with whatever the
  3210.      TARGET_EXPR is really supposed to initialize, so treat it
  3211.      as being equivalent to anything.  */
  3212.       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
  3213.        && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
  3214.        && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
  3215.       || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
  3216.           && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
  3217.           && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
  3218.     cmp = 1;
  3219.       else
  3220.     cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3221.       if (cmp <= 0)
  3222.     return cmp;
  3223.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3224.  
  3225.     case WITH_CLEANUP_EXPR:
  3226.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3227.       if (cmp <= 0)
  3228.     return cmp;
  3229.       return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
  3230.  
  3231.     case COMPONENT_REF:
  3232.       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
  3233.     return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3234.       return 0;
  3235.  
  3236.     case VAR_DECL:
  3237.     case PARM_DECL:
  3238.     case CONST_DECL:
  3239.     case FUNCTION_DECL:
  3240.       return 0;
  3241.     }
  3242.  
  3243.   /* This general rule works for most tree codes.
  3244.      All exceptions should be handled above.  */
  3245.  
  3246.   switch (TREE_CODE_CLASS (code1))
  3247.     {
  3248.       int i;
  3249.     case '1':
  3250.     case '2':
  3251.     case '<':
  3252.     case 'e':
  3253.     case 'r':
  3254.     case 's':
  3255.       cmp = 1;
  3256.       for (i=0; i<tree_code_length[(int) code1]; ++i)
  3257.     {
  3258.       cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
  3259.       if (cmp <= 0)
  3260.         return cmp;
  3261.     }
  3262.       return cmp;
  3263.     }
  3264.  
  3265.   return -1;
  3266. }
  3267.  
  3268. /* Constructors for pointer, array and function types.
  3269.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  3270.    constructed by language-dependent code, not here.)  */
  3271.  
  3272. /* Construct, lay out and return the type of pointers to TO_TYPE.
  3273.    If such a type has already been constructed, reuse it.  */
  3274.  
  3275. tree
  3276. build_pointer_type (to_type)
  3277.      tree to_type;
  3278. {
  3279.   register tree t = TYPE_POINTER_TO (to_type);
  3280.  
  3281.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3282.  
  3283.   if (t)
  3284.     return t;
  3285.  
  3286.   /* We need a new one.  Put this in the same obstack as TO_TYPE.   */
  3287.   push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
  3288.   t = make_node (POINTER_TYPE);
  3289.   pop_obstacks ();
  3290.  
  3291.   TREE_TYPE (t) = to_type;
  3292.  
  3293.   /* Record this type as the pointer to TO_TYPE.  */
  3294.   TYPE_POINTER_TO (to_type) = t;
  3295.  
  3296.   /* Lay out the type.  This function has many callers that are concerned
  3297.      with expression-construction, and this simplifies them all.
  3298.      Also, it guarantees the TYPE_SIZE is in the same obstack as the type.  */
  3299.   layout_type (t);
  3300.  
  3301.   return t;
  3302. }
  3303.  
  3304. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  3305.    MAXVAL should be the maximum value in the domain
  3306.    (one less than the length of the array).  */
  3307.  
  3308. tree
  3309. build_index_type (maxval)
  3310.      tree maxval;
  3311. {
  3312.   register tree itype = make_node (INTEGER_TYPE);
  3313.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  3314.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  3315.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  3316.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  3317.   TYPE_MODE (itype) = TYPE_MODE (sizetype);
  3318.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  3319.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  3320.   if (TREE_CODE (maxval) == INTEGER_CST)
  3321.     {
  3322.       int maxint = (int) TREE_INT_CST_LOW (maxval);
  3323.       /* If the domain should be empty, make sure the maxval
  3324.      remains -1 and is not spoiled by truncation.  */
  3325.       if (INT_CST_LT (maxval, integer_zero_node))
  3326.     {
  3327.       TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
  3328.       TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
  3329.     }
  3330.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3331.     }
  3332.   else
  3333.     return itype;
  3334. }
  3335.  
  3336. /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
  3337.    ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
  3338.    low bound LOWVAL and high bound HIGHVAL.
  3339.    if TYPE==NULL_TREE, sizetype is used. */
  3340.  
  3341. tree
  3342. build_range_type (type, lowval, highval)
  3343.      tree type, lowval, highval;
  3344. {
  3345.   register tree itype = make_node (INTEGER_TYPE);
  3346.   TREE_TYPE (itype) = type;
  3347.   if (type == NULL_TREE)
  3348.     type = sizetype;
  3349.   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
  3350.   TYPE_MIN_VALUE (itype) = convert (type, lowval);
  3351.   TYPE_MAX_VALUE (itype) = convert (type, highval);
  3352.   TYPE_MODE (itype) = TYPE_MODE (type);
  3353.   TYPE_SIZE (itype) = TYPE_SIZE (type);
  3354.   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
  3355.   if ((TREE_CODE (lowval) == INTEGER_CST)
  3356.       && (TREE_CODE (highval) == INTEGER_CST))
  3357.     {
  3358.       HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
  3359.       HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
  3360.       int maxint = (int) (highint - lowint);
  3361.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3362.     }
  3363.   else
  3364.     return itype;
  3365. }
  3366.  
  3367. /* Just like build_index_type, but takes lowval and highval instead
  3368.    of just highval (maxval). */
  3369.  
  3370. tree
  3371. build_index_2_type (lowval,highval)
  3372.      tree lowval, highval;
  3373. {
  3374.   return build_range_type (NULL_TREE, lowval, highval);
  3375. }
  3376.  
  3377. /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
  3378.    Needed because when index types are not hashed, equal index types
  3379.    built at different times appear distinct, even though structurally,
  3380.    they are not.  */
  3381.  
  3382. int
  3383. index_type_equal (itype1, itype2)
  3384.      tree itype1, itype2;
  3385. {
  3386.   if (TREE_CODE (itype1) != TREE_CODE (itype2))
  3387.     return 0;
  3388.   if (TREE_CODE (itype1) == INTEGER_TYPE)
  3389.     {
  3390.       if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
  3391.       || TYPE_MODE (itype1) != TYPE_MODE (itype2)
  3392.       || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
  3393.       || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
  3394.     return 0;
  3395.       if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
  3396.       && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
  3397.     return 1;
  3398.     }
  3399.   return 0;
  3400. }
  3401.  
  3402. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  3403.    and number of elements specified by the range of values of INDEX_TYPE.
  3404.    If such a type has already been constructed, reuse it.  */
  3405.  
  3406. tree
  3407. build_array_type (elt_type, index_type)
  3408.      tree elt_type, index_type;
  3409. {
  3410.   register tree t;
  3411.   int hashcode;
  3412.  
  3413.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  3414.     {
  3415.       error ("arrays of functions are not meaningful");
  3416.       elt_type = integer_type_node;
  3417.     }
  3418.  
  3419.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  3420.   build_pointer_type (elt_type);
  3421.  
  3422.   /* Allocate the array after the pointer type,
  3423.      in case we free it in type_hash_canon.  */
  3424.   t = make_node (ARRAY_TYPE);
  3425.   TREE_TYPE (t) = elt_type;
  3426.   TYPE_DOMAIN (t) = index_type;
  3427.  
  3428.   if (index_type == 0)
  3429.     {
  3430.       return t;
  3431.     }
  3432.  
  3433.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  3434.   t = type_hash_canon (hashcode, t);
  3435.  
  3436. #if 0 /* This led to crashes, because it could put a temporary node
  3437.      on the TYPE_NEXT_VARIANT chain of a permanent one.  */
  3438.   /* The main variant of an array type should always
  3439.      be an array whose element type is the main variant.  */
  3440.   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
  3441.     change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
  3442.                           index_type));
  3443. #endif
  3444.  
  3445.   if (TYPE_SIZE (t) == 0)
  3446.     layout_type (t);
  3447.   return t;
  3448. }
  3449.  
  3450. /* Construct, lay out and return
  3451.    the type of functions returning type VALUE_TYPE
  3452.    given arguments of types ARG_TYPES.
  3453.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  3454.    are data type nodes for the arguments of the function.
  3455.    If such a type has already been constructed, reuse it.  */
  3456.  
  3457. tree
  3458. build_function_type (value_type, arg_types)
  3459.      tree value_type, arg_types;
  3460. {
  3461.   register tree t;
  3462.   int hashcode;
  3463.  
  3464.   if (TREE_CODE (value_type) == FUNCTION_TYPE)
  3465.     {
  3466.       error ("function return type cannot be function");
  3467.       value_type = integer_type_node;
  3468.     }
  3469.  
  3470.   /* Make a node of the sort we want.  */
  3471.   t = make_node (FUNCTION_TYPE);
  3472.   TREE_TYPE (t) = value_type;
  3473.   TYPE_ARG_TYPES (t) = arg_types;
  3474.  
  3475.   /* If we already have such a type, use the old one and free this one.  */
  3476.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  3477.   t = type_hash_canon (hashcode, t);
  3478.  
  3479.   if (TYPE_SIZE (t) == 0)
  3480.     layout_type (t);
  3481.   return t;
  3482. }
  3483.  
  3484. /* Build the node for the type of references-to-TO_TYPE.  */
  3485.  
  3486. tree
  3487. build_reference_type (to_type)
  3488.      tree to_type;
  3489. {
  3490.   register tree t = TYPE_REFERENCE_TO (to_type);
  3491.   register struct obstack *ambient_obstack = current_obstack;
  3492.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  3493.  
  3494.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3495.  
  3496.   if (t)
  3497.     return t;
  3498.  
  3499.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  3500.   if (TREE_PERMANENT (to_type))
  3501.     {
  3502.       current_obstack = &permanent_obstack;
  3503.       saveable_obstack = &permanent_obstack;
  3504.     }
  3505.  
  3506.   t = make_node (REFERENCE_TYPE);
  3507.   TREE_TYPE (t) = to_type;
  3508.  
  3509.   /* Record this type as the pointer to TO_TYPE.  */
  3510.   TYPE_REFERENCE_TO (to_type) = t;
  3511.  
  3512.   layout_type (t);
  3513.  
  3514.   current_obstack = ambient_obstack;
  3515.   saveable_obstack = ambient_saveable_obstack;
  3516.   return t;
  3517. }
  3518.  
  3519. /* Construct, lay out and return the type of methods belonging to class
  3520.    BASETYPE and whose arguments and values are described by TYPE.
  3521.    If that type exists already, reuse it.
  3522.    TYPE must be a FUNCTION_TYPE node.  */
  3523.  
  3524. tree
  3525. build_method_type (basetype, type)
  3526.      tree basetype, type;
  3527. {
  3528.   register tree t;
  3529.   int hashcode;
  3530.  
  3531.   /* Make a node of the sort we want.  */
  3532.   t = make_node (METHOD_TYPE);
  3533.  
  3534.   if (TREE_CODE (type) != FUNCTION_TYPE)
  3535.     abort ();
  3536.  
  3537.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3538.   TREE_TYPE (t) = TREE_TYPE (type);
  3539.  
  3540.   /* The actual arglist for this function includes a "hidden" argument
  3541.      which is "this".  Put it into the list of argument types.  */
  3542.  
  3543.   TYPE_ARG_TYPES (t)
  3544.     = tree_cons (NULL_TREE,
  3545.          build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  3546.  
  3547.   /* If we already have such a type, use the old one and free this one.  */
  3548.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3549.   t = type_hash_canon (hashcode, t);
  3550.  
  3551.   if (TYPE_SIZE (t) == 0)
  3552.     layout_type (t);
  3553.  
  3554.   return t;
  3555. }
  3556.  
  3557. /* Construct, lay out and return the type of offsets to a value
  3558.    of type TYPE, within an object of type BASETYPE.
  3559.    If a suitable offset type exists already, reuse it.  */
  3560.  
  3561. tree
  3562. build_offset_type (basetype, type)
  3563.      tree basetype, type;
  3564. {
  3565.   register tree t;
  3566.   int hashcode;
  3567.  
  3568.   /* Make a node of the sort we want.  */
  3569.   t = make_node (OFFSET_TYPE);
  3570.  
  3571.   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3572.   TREE_TYPE (t) = type;
  3573.  
  3574.   /* If we already have such a type, use the old one and free this one.  */
  3575.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3576.   t = type_hash_canon (hashcode, t);
  3577.  
  3578.   if (TYPE_SIZE (t) == 0)
  3579.     layout_type (t);
  3580.  
  3581.   return t;
  3582. }
  3583.  
  3584. /* Create a complex type whose components are COMPONENT_TYPE.  */
  3585.  
  3586. tree
  3587. build_complex_type (component_type)
  3588.      tree component_type;
  3589. {
  3590.   register tree t;
  3591.   int hashcode;
  3592.  
  3593.   /* Make a node of the sort we want.  */
  3594.   t = make_node (COMPLEX_TYPE);
  3595.  
  3596.   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
  3597.   TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
  3598.   TYPE_READONLY (t) = TYPE_READONLY (component_type);
  3599.  
  3600.   /* If we already have such a type, use the old one and free this one.  */
  3601.   hashcode = TYPE_HASH (component_type);
  3602.   t = type_hash_canon (hashcode, t);
  3603.  
  3604.   if (TYPE_SIZE (t) == 0)
  3605.     layout_type (t);
  3606.  
  3607.   return t;
  3608. }
  3609.  
  3610. /* Return OP, stripped of any conversions to wider types as much as is safe.
  3611.    Converting the value back to OP's type makes a value equivalent to OP.
  3612.  
  3613.    If FOR_TYPE is nonzero, we return a value which, if converted to
  3614.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  3615.  
  3616.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  3617.    narrowest type that can hold the value, even if they don't exactly fit.
  3618.    Otherwise, bit-field references are changed to a narrower type
  3619.    only if they can be fetched directly from memory in that type.
  3620.  
  3621.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  3622.  
  3623.    There are some cases where the obvious value we could return
  3624.    would regenerate to OP if converted to OP's type, 
  3625.    but would not extend like OP to wider types.
  3626.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  3627.    For example, if OP is (unsigned short)(signed char)-1,
  3628.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  3629.    even though extending that to an unsigned short would regenerate OP,
  3630.    since the result of extending (signed char)-1 to (int)
  3631.    is different from (int) OP.  */
  3632.  
  3633. tree
  3634. get_unwidened (op, for_type)
  3635.      register tree op;
  3636.      tree for_type;
  3637. {
  3638.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  3639.   /* TYPE_PRECISION is safe in place of type_precision since
  3640.      pointer types are not allowed.  */
  3641.   register tree type = TREE_TYPE (op);
  3642.   register unsigned final_prec
  3643.     = TYPE_PRECISION (for_type != 0 ? for_type : type);
  3644.   register int uns
  3645.     = (for_type != 0 && for_type != type
  3646.        && final_prec > TYPE_PRECISION (type)
  3647.        && TREE_UNSIGNED (type));
  3648.   register tree win = op;
  3649.  
  3650.   while (TREE_CODE (op) == NOP_EXPR)
  3651.     {
  3652.       register int bitschange
  3653.     = TYPE_PRECISION (TREE_TYPE (op))
  3654.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3655.  
  3656.       /* Truncations are many-one so cannot be removed.
  3657.      Unless we are later going to truncate down even farther.  */
  3658.       if (bitschange < 0
  3659.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  3660.     break;
  3661.  
  3662.       /* See what's inside this conversion.  If we decide to strip it,
  3663.      we will set WIN.  */
  3664.       op = TREE_OPERAND (op, 0);
  3665.  
  3666.       /* If we have not stripped any zero-extensions (uns is 0),
  3667.      we can strip any kind of extension.
  3668.      If we have previously stripped a zero-extension,
  3669.      only zero-extensions can safely be stripped.
  3670.      Any extension can be stripped if the bits it would produce
  3671.      are all going to be discarded later by truncating to FOR_TYPE.  */
  3672.  
  3673.       if (bitschange > 0)
  3674.     {
  3675.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  3676.         win = op;
  3677.       /* TREE_UNSIGNED says whether this is a zero-extension.
  3678.          Let's avoid computing it if it does not affect WIN
  3679.          and if UNS will not be needed again.  */
  3680.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  3681.           && TREE_UNSIGNED (TREE_TYPE (op)))
  3682.         {
  3683.           uns = 1;
  3684.           win = op;
  3685.         }
  3686.     }
  3687.     }
  3688.  
  3689.   if (TREE_CODE (op) == COMPONENT_REF
  3690.       /* Since type_for_size always gives an integer type.  */
  3691.       && TREE_CODE (type) != REAL_TYPE)
  3692.     {
  3693.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3694.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  3695.  
  3696.       /* We can get this structure field in the narrowest type it fits in.
  3697.      If FOR_TYPE is 0, do this only for a field that matches the
  3698.      narrower type exactly and is aligned for it
  3699.      The resulting extension to its nominal type (a fullword type)
  3700.      must fit the same conditions as for other extensions.  */
  3701.  
  3702.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3703.       && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
  3704.       && (! uns || final_prec <= innerprec
  3705.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3706.       && type != 0)
  3707.     {
  3708.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3709.                TREE_OPERAND (op, 1));
  3710.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3711.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3712.       TREE_RAISES (win) = TREE_RAISES (op);
  3713.     }
  3714.     }
  3715.   return win;
  3716. }
  3717.  
  3718. /* Return OP or a simpler expression for a narrower value
  3719.    which can be sign-extended or zero-extended to give back OP.
  3720.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  3721.    or 0 if the value should be sign-extended.  */
  3722.  
  3723. tree
  3724. get_narrower (op, unsignedp_ptr)
  3725.      register tree op;
  3726.      int *unsignedp_ptr;
  3727. {
  3728.   register int uns = 0;
  3729.   int first = 1;
  3730.   register tree win = op;
  3731.  
  3732.   while (TREE_CODE (op) == NOP_EXPR)
  3733.     {
  3734.       register int bitschange
  3735.     = TYPE_PRECISION (TREE_TYPE (op))
  3736.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3737.  
  3738.       /* Truncations are many-one so cannot be removed.  */
  3739.       if (bitschange < 0)
  3740.     break;
  3741.  
  3742.       /* See what's inside this conversion.  If we decide to strip it,
  3743.      we will set WIN.  */
  3744.       op = TREE_OPERAND (op, 0);
  3745.  
  3746.       if (bitschange > 0)
  3747.     {
  3748.       /* An extension: the outermost one can be stripped,
  3749.          but remember whether it is zero or sign extension.  */
  3750.       if (first)
  3751.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  3752.       /* Otherwise, if a sign extension has been stripped,
  3753.          only sign extensions can now be stripped;
  3754.          if a zero extension has been stripped, only zero-extensions.  */
  3755.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  3756.         break;
  3757.       first = 0;
  3758.     }
  3759.       else /* bitschange == 0 */
  3760.     {
  3761.       /* A change in nominal type can always be stripped, but we must
  3762.          preserve the unsignedness.  */
  3763.       if (first)
  3764.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  3765.       first = 0;
  3766.     }
  3767.  
  3768.       win = op;
  3769.     }
  3770.  
  3771.   if (TREE_CODE (op) == COMPONENT_REF
  3772.       /* Since type_for_size always gives an integer type.  */
  3773.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  3774.     {
  3775.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3776.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  3777.  
  3778.       /* We can get this structure field in a narrower type that fits it,
  3779.      but the resulting extension to its nominal type (a fullword type)
  3780.      must satisfy the same conditions as for other extensions.
  3781.  
  3782.      Do this only for fields that are aligned (not bit-fields),
  3783.      because when bit-field insns will be used there is no
  3784.      advantage in doing this.  */
  3785.  
  3786.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3787.       && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
  3788.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3789.       && type != 0)
  3790.     {
  3791.       if (first)
  3792.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  3793.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3794.                TREE_OPERAND (op, 1));
  3795.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3796.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3797.       TREE_RAISES (win) = TREE_RAISES (op);
  3798.     }
  3799.     }
  3800.   *unsignedp_ptr = uns;
  3801.   return win;
  3802. }
  3803.  
  3804. /* Return the precision of a type, for arithmetic purposes.
  3805.    Supports all types on which arithmetic is possible
  3806.    (including pointer types).
  3807.    It's not clear yet what will be right for complex types.  */
  3808.  
  3809. int
  3810. type_precision (type)
  3811.      register tree type;
  3812. {
  3813.   return ((TREE_CODE (type) == INTEGER_TYPE
  3814.        || TREE_CODE (type) == ENUMERAL_TYPE
  3815.        || TREE_CODE (type) == REAL_TYPE)
  3816.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  3817. }
  3818.  
  3819. /* Nonzero if integer constant C has a value that is permissible
  3820.    for type TYPE (an INTEGER_TYPE).  */
  3821.  
  3822. int
  3823. int_fits_type_p (c, type)
  3824.      tree c, type;
  3825. {
  3826.   if (TREE_UNSIGNED (type))
  3827.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  3828.            && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
  3829.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  3830.           && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))));
  3831.   else
  3832.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  3833.            && INT_CST_LT (TYPE_MAX_VALUE (type), c))
  3834.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  3835.           && INT_CST_LT (c, TYPE_MIN_VALUE (type))));
  3836. }
  3837.  
  3838. /* Return the innermost context enclosing DECL that is
  3839.    a FUNCTION_DECL, or zero if none.  */
  3840.  
  3841. tree
  3842. decl_function_context (decl)
  3843.      tree decl;
  3844. {
  3845.   tree context;
  3846.  
  3847.   if (TREE_CODE (decl) == ERROR_MARK)
  3848.     return 0;
  3849.  
  3850.   if (TREE_CODE (decl) == SAVE_EXPR)
  3851.     context = SAVE_EXPR_CONTEXT (decl);
  3852.   else
  3853.     context = DECL_CONTEXT (decl);
  3854.  
  3855.   while (context && TREE_CODE (context) != FUNCTION_DECL)
  3856.     {
  3857.       if (TREE_CODE (context) == RECORD_TYPE
  3858.       || TREE_CODE (context) == UNION_TYPE)
  3859.     context = NULL_TREE;
  3860.       else if (TREE_CODE (context) == TYPE_DECL)
  3861.     context = DECL_CONTEXT (context);
  3862.       else if (TREE_CODE (context) == BLOCK)
  3863.     context = BLOCK_SUPERCONTEXT (context);
  3864.       else
  3865.     /* Unhandled CONTEXT !?  */
  3866.     abort ();
  3867.     }
  3868.  
  3869.   return context;
  3870. }
  3871.  
  3872. /* Return the innermost context enclosing DECL that is
  3873.    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
  3874.    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
  3875.  
  3876. tree
  3877. decl_type_context (decl)
  3878.      tree decl;
  3879. {
  3880.   tree context = DECL_CONTEXT (decl);
  3881.  
  3882.   while (context)
  3883.     {
  3884.       if (TREE_CODE (context) == RECORD_TYPE
  3885.       || TREE_CODE (context) == UNION_TYPE
  3886.       || TREE_CODE (context) == QUAL_UNION_TYPE)
  3887.     return context;
  3888.       if (TREE_CODE (context) == TYPE_DECL
  3889.       || TREE_CODE (context) == FUNCTION_DECL)
  3890.     context = DECL_CONTEXT (context);
  3891.       else if (TREE_CODE (context) == BLOCK)
  3892.     context = BLOCK_SUPERCONTEXT (context);
  3893.       else
  3894.     /* Unhandled CONTEXT!?  */
  3895.     abort ();
  3896.     }
  3897.   return NULL_TREE;
  3898. }
  3899.  
  3900. void
  3901. print_obstack_statistics (str, o)
  3902.      char *str;
  3903.      struct obstack *o;
  3904. {
  3905.   struct _obstack_chunk *chunk = o->chunk;
  3906.   int n_chunks = 0;
  3907.   int n_alloc = 0;
  3908.  
  3909.   while (chunk)
  3910.     {
  3911.       n_chunks += 1;
  3912.       n_alloc += chunk->limit - &chunk->contents[0];
  3913.       chunk = chunk->prev;
  3914.     }
  3915.   fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
  3916.        str, n_alloc, n_chunks);
  3917. }
  3918. void
  3919. dump_tree_statistics ()
  3920. {
  3921.   int i;
  3922.   int total_nodes, total_bytes;
  3923.  
  3924.   fprintf (stderr, "\n??? tree nodes created\n\n");
  3925. #ifdef GATHER_STATISTICS
  3926.   fprintf (stderr, "Kind                  Nodes     Bytes\n");
  3927.   fprintf (stderr, "-------------------------------------\n");
  3928.   total_nodes = total_bytes = 0;
  3929.   for (i = 0; i < (int) all_kinds; i++)
  3930.     {
  3931.       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
  3932.            tree_node_counts[i], tree_node_sizes[i]);
  3933.       total_nodes += tree_node_counts[i];
  3934.       total_bytes += tree_node_sizes[i];
  3935.     }
  3936.   fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);
  3937.   fprintf (stderr, "-------------------------------------\n");
  3938.   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
  3939.   fprintf (stderr, "-------------------------------------\n");
  3940. #else
  3941.   fprintf (stderr, "(No per-node statistics)\n");
  3942. #endif
  3943.   print_lang_statistics ();
  3944. }
  3945.  
  3946. #define FILE_FUNCTION_PREFIX_LEN 9
  3947.  
  3948. #ifndef NO_DOLLAR_IN_LABEL
  3949. #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
  3950. #else /* NO_DOLLAR_IN_LABEL */
  3951. #ifndef NO_DOT_IN_LABEL
  3952. #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
  3953. #else /* NO_DOT_IN_LABEL */
  3954. #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
  3955. #endif    /* NO_DOT_IN_LABEL */
  3956. #endif    /* NO_DOLLAR_IN_LABEL */
  3957.  
  3958. extern char * first_global_object_name;
  3959.  
  3960. /* If KIND=='I', return a suitable global initializer (constructor) name.
  3961.    If KIND=='D', return a suitable global clean-up (destructor) name. */
  3962.  
  3963. tree
  3964. get_file_function_name (kind)
  3965.      int kind;
  3966. {
  3967.   char *buf;
  3968.   register char *p;
  3969.  
  3970.   if (first_global_object_name)
  3971.     p = first_global_object_name;
  3972.   else if (main_input_filename)
  3973.     p = main_input_filename;
  3974.   else
  3975.     p = input_filename;
  3976.  
  3977.   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p));
  3978.  
  3979.   /* Set up the name of the file-level functions we may need.  */
  3980.   /* Use a global object (which is already required to be unique over
  3981.      the program) rather than the file name (which imposes extra
  3982.      constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */
  3983.   sprintf (buf, FILE_FUNCTION_FORMAT, p);
  3984.  
  3985.   /* Don't need to pull wierd characters out of global names.  */
  3986.   if (p != first_global_object_name)
  3987.     {
  3988.       for (p = buf+11; *p; p++)
  3989.     if (! ((*p >= '0' && *p <= '9')
  3990. #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
  3991. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  3992.            || *p == '.'
  3993. #endif
  3994. #endif
  3995. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  3996.            || *p == '$'
  3997. #endif
  3998. #ifndef NO_DOT_IN_LABEL        /* this for `.'; unlikely, but... */
  3999.            || *p == '.'
  4000. #endif
  4001.            || (*p >= 'A' && *p <= 'Z')
  4002.            || (*p >= 'a' && *p <= 'z')))
  4003.       *p = '_';
  4004.     }
  4005.  
  4006.   buf[FILE_FUNCTION_PREFIX_LEN] = kind;
  4007.  
  4008.   return get_identifier (buf);
  4009. }
  4010.  
  4011. /* Expand (the constant part of) a SET_TYPE CONTRUCTOR node.
  4012.    The result is placed in BUFFER (which has length BIT_SIZE),
  4013.    with one bit in each char ('\000' or '\001').
  4014.  
  4015.    If the constructor is constant, NULL_TREE is returned.
  4016.    Otherwise, a TREE_LIST of the non-constant elements is emitted. */
  4017.  
  4018. tree
  4019. get_set_constructor_bits (init, buffer, bit_size)
  4020.      tree init;
  4021.      char *buffer;
  4022.      int bit_size;
  4023. {
  4024.   int i;
  4025.   tree vals;
  4026.   HOST_WIDE_INT domain_min
  4027.     = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
  4028.   tree non_const_bits = NULL_TREE;
  4029.   for (i = 0; i < bit_size; i++)
  4030.     buffer[i] = 0;
  4031.  
  4032.   for (vals = TREE_OPERAND (init, 1); 
  4033.        vals != NULL_TREE; vals = TREE_CHAIN (vals))
  4034.     {
  4035.       if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
  4036.       || (TREE_PURPOSE (vals) != NULL_TREE
  4037.           && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
  4038.     non_const_bits =
  4039.       tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
  4040.       else if (TREE_PURPOSE (vals) != NULL_TREE)
  4041.     {
  4042.       /* Set a range of bits to ones. */
  4043.       HOST_WIDE_INT lo_index
  4044.         = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
  4045.       HOST_WIDE_INT hi_index
  4046.         = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
  4047.       if (lo_index < 0 || lo_index >= bit_size
  4048.         || hi_index < 0 || hi_index >= bit_size)
  4049.         abort ();
  4050.       for ( ; lo_index <= hi_index; lo_index++)
  4051.         buffer[lo_index] = 1;
  4052.     }
  4053.       else
  4054.     {
  4055.       /* Set a single bit to one. */
  4056.       HOST_WIDE_INT index
  4057.         = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
  4058.       if (index < 0 || index >= bit_size)
  4059.         {
  4060.           error ("invalid initializer for bit string");
  4061.           return NULL_TREE;
  4062.         }
  4063.       buffer[index] = 1;
  4064.     }
  4065.     }
  4066.   return non_const_bits;
  4067. }
  4068.  
  4069. /* Expand (the constant part of) a SET_TYPE CONTRUCTOR node.
  4070.    The result is placed in BUFFER (which is an array of WD_SIZE
  4071.    words).  TYPE_ALIGN bits are stored in each element of BUFFER.
  4072.    If the constructor is constant, NULL_TREE is returned.
  4073.    Otherwise, a TREE_LIST of the non-constant elements is emitted. */
  4074.  
  4075. tree
  4076. get_set_constructor_words (init, buffer, wd_size)
  4077.      tree init;
  4078.      HOST_WIDE_INT *buffer;
  4079.      int wd_size;
  4080. {
  4081.   int i;
  4082.   tree vals = TREE_OPERAND (init, 1);
  4083.   int set_word_size = TYPE_ALIGN (TREE_TYPE (init));
  4084.   int bit_size = wd_size * set_word_size;
  4085.   int bit_pos = 0;
  4086.   HOST_WIDE_INT *wordp = buffer;
  4087.   char *bit_buffer = (char*)alloca(bit_size);
  4088.   tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
  4089.  
  4090.   for (i = 0; i < wd_size; i++)
  4091.     buffer[i] = 0;
  4092.  
  4093.   for (i = 0; i < bit_size; i++)
  4094.     {
  4095.       if (bit_buffer[i])
  4096.     {
  4097. #if BITS_BIG_ENDIAN
  4098.       *wordp |= (1 << (set_word_size - 1 - bit_pos));
  4099. #else
  4100.       *wordp |= 1 << bit_pos;
  4101. #endif
  4102.     }
  4103.       bit_pos++;
  4104.       if (bit_pos >= set_word_size)
  4105.     bit_pos = 0, wordp++;
  4106.     }
  4107.   return non_const_bits;
  4108. }
  4109.